[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2011-04-22
Medium Priority
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
  • 3
LVL 17

Expert Comment

by:Carlos Villegas
ID: 35447968
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

Carlos Villegas earned 2000 total points
ID: 35448218
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


Author Closing Comment

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

Thanks for your help
LVL 17

Expert Comment

by:Carlos Villegas
ID: 35504398
Good to know buddy

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month20 days, 5 hours left to enroll

872 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