1
votes

I am trying to create WCF service that can receive MTOM encoded messages. I do not have client that sends MTOM encoded messages, however I do have message example (that's why I am trying to use Postman).

Request example:

Content-Type: multipart/related; type="application/xop+xml"; boundary="uuid:83d3b2a6-5437-4366-bfb1-6f7c8b49add5"; start=""; start-info="application/soap+xml; action=\"urn:test:test1:ResponseInputMessage\""

Payload: --uuid:83d3b2a6-5437-4366-bfb1-6f7c8b49add5 Content-Type: application/xop+xml; charset=UTF-8; type="application/soap+xml; action=\"urn:test:test1:ResponseInputMessage\"" Content-Transfer-Encoding: binary Content-ID:

... --uuid:83d3b2a6-5437-4366-bfb1-6f7c8b49add5--

Postman: enter image description here enter image description here

Service contract:

[ServiceContract]
public interface IResponseService
{
    [OperationContract]
    AcknowledgementType ResponseInputMessage(RegistryResponseType registryResponse);
}

Web.config:

<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.6.1" />
    <httpRuntime targetFramework="4.6.1"/>
  </system.web>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="wsHttpMtomBinding" messageEncoding="Mtom" />
      </wsHttpBinding>
    </bindings>
<services>
  <service name="MySvc.ResponseService">
    <endpoint address="ResponseService.svc" contract="MySvc.IResponseService" binding="wsHttpBinding" bindingConfiguration="wsHttpMtomBinding"></endpoint>
  </service>
</services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="wsHttpBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>
  </system.webServer>
</configuration>

WSDL (http://localhost:50809/ResponseService.svc?wsdl) displays:

<soap12:address location="http://localhost:50809/ResponseService.svc/ResponseService.svc"/>

When I send a request to http://localhost:50809/ResponseService.svc/ResponseService.svc Postman says Could not get any response. If I send a request to http://localhost:50809/ResponseService.svc is returns 404.

Please suggest what I am missing?

Thanks in advance

1

1 Answers

2
votes

Why MTOM?

The preferred approach to send large binary messages in WCF is to use MTOM message encoding. MTOM is an interoperable standard and stands for Message Transmission Optimization Mechanism. MTOM does not base64 encode data. This also means, the additional processing overhead to base64 encode and decode data is removed. Hence, MTOM can significantly improve the overall message transfer performance.

Set messageEncoding="Mtom" in both the WCF service and the client if possible.

 <bindings>
      <wsHttpBinding>
        <binding name="wsHttpMtomBinding" messageEncoding="Mtom"
                 maxReceivedMessageSize="700000">
          <readerQuotas maxArrayLength="700000"/>
        </binding>
      </wsHttpBinding>

Content Type of MTOM will be is multipart/related.