.Net ramblings
# Thursday, 22 December 2005
MTOM error: The request failed with HTTP status 415: Unsupported media type
I'm new to MTOM, and i encountered this error while developing a WSE 3.0 application with .net.
The request failed with HTTP status 415: Unsupported media type

Explanation 1 - Basic Configuration Error

After a lot of digging around and comparing my code with the MTOM sample bundled with WSE3, i found out it was because i was missing a setting called "soapServerProtocolFactory" in my web.config, shown below.  I didn't think i needed to have a Protocol Factory (whatever that is!), but apparently I do. It works fine now that i added that section.

This is what my web.config looks like:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="microsoft.web.services3" type="Microsoft.Web.Services3.Configuration.WebServicesConfiguration, Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</configSections>
<appSettings>
<add key="UploadPath" value="Upload" />
</appSettings>
<system.web>
<webServices>
<soapServerProtocolFactory type="Microsoft.Web.Services3.WseProtocolFactory, Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<soapExtensionImporterTypes>
<add type="Microsoft.Web.Services3.Description.WseExtensionImporter, Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</soapExtensionImporterTypes>
</webServices>
<compilation>
<assemblies>
<add assembly="Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
</system.web>
<microsoft.web.services3>
<messaging>
<mtom serverMode="optional" />
</messaging>
</microsoft.web.services3>
</configuration>
My app.config for the Windows Client looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="microsoft.web.services3" type="Microsoft.Web.Services3.Configuration.WebServicesConfiguration, Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="UploadWinClient.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<microsoft.web.services3>
<messaging>
<mtom clientMode="On" />
</messaging>
</microsoft.web.services3>
<applicationSettings>
<UploadWinClient.Properties.Settings>
<setting name="UploadWinClient_MTOM_WebService_MTOM" serializeAs="String">
<value>http://localhost:1423/UploadWebClient/MTOM.asmx</value>
</setting>
</UploadWinClient.Properties.Settings>
</applicationSettings>
</configuration>

Explanation 2 - Strange Behaviour with Web Service instances...

if you're configuration is already correct, then the following may be of interest.  i came across this error in a winforms application, that has a class library with an MTOM web service in it.  my code had something like this:
myClassLibrary.WebService = this.WebService;
i was doing this because i had an instance of the web service in the win form, authenticated with a cookie in its CookieContainer property, and i wanted to replace the web service that the class library was using with the one from my win-form.  however this caused the 415 error to appear sporadically all over the place.  the fix was to just replace the CookieContainer instead of the entire web service instance.  like so:
myClassLibrary.WebService.CookieContainer = this.WebService.CookieContainer;

now i get no errors.  weird huh?

Thursday, 22 December 2005 16:13:34 (GMT Standard Time, UTC+00:00)  #    Comments [7]  Asp.Net

Tuesday, 07 February 2006 16:48:31 (GMT Standard Time, UTC+00:00)
Thanks for the post! I'm also just getting started with WSE 3.0 and MTOM currently, and I ran into the HTTP 415 issue. A Google search for "MTOM HTTP 415" brought me here, and I was able to quickly fix the problem!

For reference, instead of editing your web.config directly, in Visual Studio 2005, you can right-click your web service project in Solution Explorer, select "WSE Settings 3.0...", then on the dialog that appears, on the General tab, check the "Enable Microsoft Web Services Enhancement Soap Protocol Factory".
Tuesday, 19 February 2008 10:53:26 (GMT Standard Time, UTC+00:00)
Hi Tim,

I also ran into this, but I only have it with one person connecting to my webservice, do you maybe know why only one client will have this issue. I take it that it should be a app.config issue on the client side.

thanks, MK
Mario Kielblock
Wednesday, 12 March 2008 13:41:15 (GMT Standard Time, UTC+00:00)
Hi All,

I've been getting the HTTP Status 415 with my MTOM.
The "Explaination 1" change was already in place.

I have my MTOM in a class library as described in "Explaination 2" but I believe I am already passing in the Cookie Container as follows:

[code]
private bool AuthenticateWebService()
{
// send a HTTP web request to the login.aspx page, using the querystring to pass in username and password
string postData = String.Format("?Username={0}&Password={1}", this.txtUsername.Text, this.txtPassword.Text);
string url = this.fileTransferDownload1.WebService.Url.Replace("MTOM.asmx", "") + "Login.aspx" + postData; // get the path of the login page, assuming it is in the same folder as the web service
HttpWebRequest req = HttpWebRequest.Create(url) as HttpWebRequest;
req.CookieContainer = new CookieContainer();
HttpWebResponse response = (HttpWebResponse) req.GetResponse();

// copy the cookie container to the web services
this.fileTransferDownload1.WebService.CookieContainer = req.CookieContainer;

return (response.Cookies.Count > 0); // true if the server sent an auth cookie, i.e. authenticated successfully
}
[/code]
Chris Walsh
Wednesday, 12 March 2008 13:49:10 (GMT Standard Time, UTC+00:00)
PS: Could changing web.config on the web service from:

<messaging>
<mtom serverMode="Always" />
</messaging>

to:

<messaging>
<mtom serverMode="optional" />
</messaging>

This is the only other difference that I can see between your web.config and mine.
Chris Walsh
Wednesday, 12 March 2008 13:52:10 (GMT Standard Time, UTC+00:00)
Hi Chris,
I would suggest consuming a basic "HelloWorld" web service first and get that working, this will help troubleshoot any server config issues you may have.
Then once that is working you can turn on forms authentication on the server and try authenticating the win forms client.
Good luck
Tim
tim
Friday, 05 March 2010 18:00:09 (GMT Standard Time, UTC+00:00)
Just to mention that I had this problem in version 2 (which I am stuck with) and I had to add the following:

<soapExtensionTypes>
<add type="Microsoft.Web.Services2.WebServicesExtension, Microsoft.Web.Services2, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
priority="1" group="0" />
</soapExtensionTypes>
</webServices>

</system.web>
</configuration>
Thursday, 14 April 2011 03:02:31 (GMT Daylight Time, UTC+01:00)
Hi Tim, everyone,

I am wondering you have or are aware of anything that encapsulates MTOM like a activex control that I can call from a vb.net 2008 project. I dont mind paying, I just cant find anything like this and dont want to develop this in vb.net from scratch.

Cheers,

Michael
Michael
OpenID
Please login with either your OpenID above, or your details below.
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

[Captcha]Enter the code shown (prevents robots):

Live Comment Preview