none
MTOM in C#: client app looking for base64binary, svcutil-generated config doesn't match samples. RRS feed

  • Question

  • I hope this is the right forum. I seem to have a hard time with that on MSDN. =P

    Background info: building a webservice-consuming client in C#. Used svcutil to auto-generate the proxy class. The web service is set up to send PDF attachments via MTOM, and when I use the API call from the proxy to try to do so, I get the following error:

    Client found response content type of 'multipart/related; boundary="MIMEBoundaryurn_uuid_5D7E9AC12266BFFBDB1370543444063"; start-info="text/xml"; type="text/xml"; start="<0.urn:uuid:5D7E9AC12266BFFBDB1370543444064@apache.org>"', but expected 'text/xml'.



    ...which I've found means that the client isn't properly configured for MTOM. Okay, cool, there are some examples of how to change the config to make it so. Here's where I'm tripping up, though--all of the examples that I've found so far have the config file mapped differently than how mine is set up. The examples are set up with two items in the system.serviceModel section, one for the bindings and one for the client endpoint, which contains the endpoint address. My auto-generated config plops the address into the applicationSettings, and, well, I'm confused. :( Here they are, side by side:


    Examples:

    <?xml version="1.0"?>
        <configuration>
          <system.serviceModel>
            <bindings>
              <wsHttpBinding>
                <binding name="WSHttpBinding_IUpload" messageEncoding="Mtom"/>
              </wsHttpBinding>
            </bindings>
            <client>
              <endpoint address="http://localhost/ServiceModelSamples/service.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IUpload" contract="IUpload">
              </endpoint>
            </client>
          </system.serviceModel>
        <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>



    Mine:

    <?xml version="1.0" encoding="utf-8" ?>
        <configuration>
            <configSections>
                <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=----------------" >
                  <section name="TWS.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=----------------" requirePermission="false" />
                </sectionGroup>
              </configSections>
              <applicationSettings>
                <TWS.Properties.Settings>
                  <setting name="TWS_WebService_WsApiService" serializeAs="String">
                    <value>https://www.<redacted>.com/services/WsApiService/</value>
                  </setting>
                </TWS.Properties.Settings>
              </applicationSettings>
            </configuration>

       



    Here's how the API call itself is set up in the proxy class:

    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://localhost:8080/getStiDoc", RequestNamespace="http://www.<redacted>.com/ws/schemas", ResponseNamespace="http://www.<redacted>.com/ws/schemas", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] [return: System.Xml.Serialization.XmlElementAttribute("doc", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, DataType="base64Binary", IsNullable=true)] public byte[] getDoc([System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=true)] string username, [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, DataType="integer", IsNullable=true)] string id) {                 object[] results = this.Invoke("getDoc", new object[] {                             username,                             id});               return ((byte[])(results[0]));

                }



    My question is this: How should I specify that the message type is MTOM and not base64binary?


    Friday, June 7, 2013 1:52 PM

Answers

  • Finally found the answers on my own. In order to get the proxy class set up properly (i.e. in WCF-compliant form instead of WSE), I had to use the command-line version of svcutil instead of the "Add Web Reference" button in Add Service Reference -> Advanced. After I did that, I was able to add messageBinding="Mtom". Still having trouble with configuring the certificate, but that is a far, far smaller issue.

    • Marked as answer by Antessima Wednesday, June 12, 2013 1:59 PM
    Wednesday, June 12, 2013 1:59 PM

All replies

  • Finally found the answers on my own. In order to get the proxy class set up properly (i.e. in WCF-compliant form instead of WSE), I had to use the command-line version of svcutil instead of the "Add Web Reference" button in Add Service Reference -> Advanced. After I did that, I was able to add messageBinding="Mtom". Still having trouble with configuring the certificate, but that is a far, far smaller issue.

    • Marked as answer by Antessima Wednesday, June 12, 2013 1:59 PM
    Wednesday, June 12, 2013 1:59 PM
  • Hi,

    I am very glad that you have solved your problem by yourself.

    If you have any other problem, welcome to post it in the WCF Forums.

    Best Regards.


    Amy Peng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, June 13, 2013 5:42 AM
    Moderator