从Postman向WCF服务发送MTOM编码请求

时间:2018-01-19 11:28:25

标签: c# web-services wcf postman mtom

我正在尝试创建可以接收MTOM编码消息的WCF服务。我没有发送MTOM编码消息的客户端,但是我确实有消息示例(这就是我尝试使用Postman的原因)。

请求示例:

  

内容类型:multipart / related;类型= “应​​用/ XOP + xml” 的;   边界= “UUID:83d3b2a6-5437-4366-bfb1-6f7c8b49add5”;   开始= “”;   启动信息=“应用/肥皂+ xml的;   行动= \ “瓮:试验:TEST1:ResponseInputMessage \”“

     

有效负载: - uuid:83d3b2a6-5437-4366-bfb1-6f7c8b49add5内容类型:   应用/ XOP + xml的;字符集= UTF-8;类型=“应用/肥皂+ xml的;   行动= \ “瓮:试验:TEST1:ResponseInputMessage \””   内容传输编码:二进制内容ID:   

     

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

邮差: enter image description here enter image description here

服务合同

[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)显示:

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

当我向http://localhost:50809/ResponseService.svc/ResponseService.svc发送请求时,邮递员说Could not get any response。如果我向http://localhost:50809/ResponseService.svc发送请求,则返回404

请建议我缺少什么?

提前致谢

1 个答案:

答案 0 :(得分:1)

为什么 MTOM

在WCF中发送大型二进制消息的首选方法是使用MTOM消息编码。 MTOM是一种可互操作的标准,代表消息传输优化机制。 MTOM不对base64编码数据。这也意味着,删除了base64编码和解码数据的额外处理开销。因此,MTOM可以显着提高整体消息传输性能。

如果可能,在WCF服务和客户端中设置messageEncoding =“Mtom”。

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

内容MTOM类型为多部分/相关