.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