<system.serviceModel>
<services>
<service name="MyService.Service"
behaviorConfiguration="MyService.Service1Behavior">
<!-- Service Endpoints -->
<endpoint address=""
binding="webHttpBinding"
behaviorConfiguration="custom"
contract="MyService.ISmsMessageService">
</endpoint>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="custom">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="MyService.Service1Behavior">
<serviceMetadata httpGetEnabled="true"/>
serviceDebug
includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
The two larger texts are the keys to making this work in the webconfig file. There is another replacement for the <webHttp> element: <enableWebScript> which is used in AJAX calls.
The following code shows how to use the HttpRequestMessageProperty and the HttpResponseMessageProperty.
public Message ProcessMessage(Message request)
{
Message response = null;
HttpRequestMessageProperty requestProperties =
(HttpRequestMessageProperty)request.Properties
[HttpRequestMessageProperty.Name];
if (requestProperties != null)
{
if (String.Equals("GET", requestProperties.Method,
StringComparison.OrdinalIgnoreCase))
{
//We will process the request at this point.
string queryString = requestProperties.QueryString
if (!string.IsNullOrEmpty(queryString))
{
this.ProcessSmsResponse(queryString);
}
else
{
WriteToTextLog.WriteLine("Empty Query String");
}
}
else
{
response = Message.CreateMessage(MessageVersion.None,
String.Empty,
String.Empty);
HttpResponseMessageProperty rp = new
HttpResponseMessageProperty();
rp.StatusCode = HttpStatusCode.MethodNotAllowed;
response.Properties.Add
(HttpResponseMessageProperty.Name,
responseProperty);
}
}
else
{
throw new InvalidOperationException
("This service requires the HTTP transport");
}
return response;
}
That’s about all there is to it. I can’t believe its not mentioned anywhere in the Mainstream literature. But, oh well, I stumbled across what I needed, when I needed it and was able to solve my problem and deliver my code to the client. I just hope that this post may help someone avoid the hurdles that I had to jump over the last few weeks.