We help IT Professionals succeed at work.

Hoist the colors! We’ve added location flags to usernames sitewide, so it's easier to connect with the global community on EE. View My Profile

x

Problems when performing HTTP Post to WCF Service (Error 415: Cannot process the message because of content type mismatch)

nkewney
nkewney asked
on
9,471 Views
Last Modified: 2012-05-11
Hi Everyone,

I'm having real problems posting data to a WCF service. I would be very grateful if anybody could help me diagnose the error I'm receiving below.

The remote server returned an error: (415) Cannot process the message because the content type 'application/x-www-form-urlencoded' was not the expected type 'text/xml; charset=utf-8'..

I'm sending data to the service via a simple HTTP post as content type = "application/x-www-form-urlencoded".

My WCF interface and config is pasted below.
[ServiceContract]
public interface ITextService
{
[WebInvoke(UriTemplate = "invoke", Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
[OperationContract]
string PostData(Stream input);
}


[OperationBehavior]
public string PostData(Stream input)
{......



<?xml version="1.0"?>
<configuration>
<system.web>
<webServices>
<protocols>
<add name="HttpPost" />
</protocols>
</webServices>
<compilation debug="true"/>
<customErrors mode="Off">

</customErrors>
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's 
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="WebConfiguration"
maxBufferSize="65536"
maxReceivedMessageSize="2000000000"
transferMode="Streamed">
</binding>
</webHttpBinding>
<basicHttpBinding>
<binding name="StreamedHttp" transferMode="Streamed" maxBufferSize="2147483647" MaxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="SimFreeGateway.TextService" behaviorConfiguration="SimFreeGatewayBehavior">
<endpoint address="" binding="basicHttpBinding" contract="SimFreeGateway.ITextService" bindingConfiguration="StreamedHttp" bindingNamespace="xxx" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="WebBehavior">
<serviceDebug httpHelpPageEnabled="false" httpsHelpPageEnabled="false" />
<serviceMetadata />
</behavior>
<behavior name="SimFreeGatewayBehavior">
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>

Open in new window

Comment
Watch Question

Carlos VillegasFull Stack .NET Developer

Commented:
Hello, I think that you need to use a WebHttpBinding endpoint instead of BasicHttpBinding, I did that some time agon, more info:

The Web Programming Model allows developers to expose Web services through HTTP requests that use "plain old XML" (POX) style messaging instead of SOAP-based messaging. For clients to communicate with a service using HTTP requests, an endpoint of the service must be configured with the WebHttpBinding that has the WebHttpBehavior attached to it. The WCF Web Programming Model also requires that the individual service operations are annotated with the WebGetAttribute or WebInvokeAttribute attributes. This defines a mapping from a URI and HTTP method to the service operation, as well as the format of the messages used to call the operation and return the results. Support in for syndication and ASP.AJAX integration are both built on top of the WCF Web Programming Model.
Source:
http://msdn.microsoft.com/en-us/library/system.servicemodel.webhttpbinding.aspx
Full Stack .NET Developer
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
This solved my problem and was an oversight on my part.

Thanks for your help
Carlos VillegasFull Stack .NET Developer

Commented:
Good to know buddy

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.