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

Posted on 2011-04-22
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.
public interface ITextService
[WebInvoke(UriTemplate = "invoke", Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
string PostData(Stream input);

public string PostData(Stream input)

<?xml version="1.0"?>
<add name="HttpPost" />
<compilation debug="true"/>
<customErrors mode="Off">

<!-- 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. -->
<binding name="WebConfiguration"
<binding name="StreamedHttp" transferMode="Streamed" maxBufferSize="2147483647" MaxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<service name="SimFreeGateway.TextService" behaviorConfiguration="SimFreeGatewayBehavior">
<endpoint address="" binding="basicHttpBinding" contract="SimFreeGateway.ITextService" bindingConfiguration="StreamedHttp" bindingNamespace="xxx" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex"/>
<behavior name="WebBehavior">
<webHttp />
<behavior name="WebBehavior">
<serviceDebug httpHelpPageEnabled="false" httpsHelpPageEnabled="false" />
<serviceMetadata />
<behavior name="SimFreeGatewayBehavior">
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata httpGetEnabled="true" />
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>

Open in new window

Question by:nkewney
    LVL 17

    Expert Comment

    by:Carlos Villegas
    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.
    LVL 17

    Accepted Solution

    Try changing this line in your config:
    <endpoint address="" binding="basicHttpBinding" contract="SimFreeGateway.ITextService" bindingConfiguration="StreamedHttp" bindingNamespace="xxx" />

    Open in new window

    For this:
    <endpoint address="" binding="webHttpBinding" contract="SimFreeGateway.ITextService" bindingConfiguration="WebConfiguration" bindingNamespace="xxx" />

    Open in new window

    LVL 1

    Author Closing Comment

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

    Thanks for your help
    LVL 17

    Expert Comment

    by:Carlos Villegas
    Good to know buddy

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now