title: SOAP/MTOM: Problems with VS-generated proxy class and handling PDF attachments
body: <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:</p>
  
  <p><code>Client found response content type of 'multipart/related; boundary="MIMEBoundaryurn_uuid_5D7E9AC12266BFFBDB1370543444063"; start-info="text/xml"; type="text/xml"; start="&lt;0.urn:uuid:5D7E9AC12266BFFBDB1370543444064@apache.org&gt;"', but expected 'text/xml'.</code></p>
  
  <p>...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 <code>system.serviceModel</code> 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 <code>applicationSettings</code>, and, well, I'm confused. :( Here they are, side by side:</p>
  
  <p>Examples:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
    &lt;system.serviceModel&gt;
      &lt;bindings&gt;
        &lt;wsHttpBinding&gt;
          &lt;binding name="WSHttpBinding_IUpload" messageEncoding="Mtom"/&gt;
        &lt;/wsHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;client&gt;
        &lt;endpoint address="http://localhost/ServiceModelSamples/service.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IUpload" contract="IUpload"&gt;
        &lt;/endpoint&gt;
      &lt;/client&gt;
    &lt;/system.serviceModel&gt;
  &lt;startup&gt;&lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/&gt;&lt;/startup&gt;&lt;/configuration&gt;
  </code></pre>
  
  <p>Mine:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
      &lt;configSections&gt;
          &lt;sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=----------------" &gt;
            &lt;section name="TWS.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=----------------" requirePermission="false" /&gt;
          &lt;/sectionGroup&gt;
        &lt;/configSections&gt;
        &lt;applicationSettings&gt;
          &lt;TWS.Properties.Settings&gt;
            &lt;setting name="TWS_WebService_WsApiService" serializeAs="String"&gt;
              &lt;value&gt;https://www.&lt;redacted&gt;.com/services/WsApiService/&lt;/value&gt;
            &lt;/setting&gt;
          &lt;/TWS.Properties.Settings&gt;
        &lt;/applicationSettings&gt;
      &lt;/configuration&gt;
  </code></pre>
  
  <p>Here's how the API call itself is set up in the proxy class:</p>
  
  <pre><code>[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://localhost:8080/getStiDoc", RequestNamespace="http://www.&lt;redacted&gt;.com/ws/schemas", ResponseNamespace="http://www.&lt;redacted&gt;.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]));
          }
  </code></pre>
  
  <p>My question is this: With how my config file is set up, how should I add the appropriate bindings to ensure that it looks for MTOM instead of base64 binary?</p>