Reputation: 11
I built a wcf service according to this post of stackoverflow: How to send xml via post with wcf but I am getting this error :
The remote server returned an error: (415) Cannot process the message because the content type 'application/xml' was not the expected type 'text/xml; charset=utf-8'..
I think there is somethimg wrong with my Web.config I am posting it here:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service name="BridgeService.BridgeData" behaviorConfiguration="RESTBehavior">
<endpoint address="" binding="basicHttpBinding" contract="BridgeService.IBridgeData" behaviorConfiguration="MyEndpointBehavior">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:10912/Vishi/BridgeService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="RESTBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="MyEndpointBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Here is Interface:
[ServiceContract]
public interface IBridgeData
{
[OperationContract]
[WebInvoke(Method = "POST",
UriTemplate = "InsertData",
RequestFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Bare)]
string InsertData(transport_xml transport_xml);
}
And calling is same like the referenced post of Stackoverflow. please help me. Thanks in Advance!!
Upvotes: 1
Views: 3741
Reputation: 4569
Change your Binding to webHttpBinding.
binding="basicHttpBinding"
And make sure that when you make request, don't forget to add Content-Type
like:
Content-Type: application/xml;charset=utf-8
Upvotes: 2
Reputation: 2246
to use a Rest behavior you must have webHttpBinding. Try changing that.
Upvotes: 1