如何创建接受MTOM编码请求的WCF服务

时间:2018-01-22 18:37:55

标签: c# web-services wcf soap mtom

我需要创建能够接受从基于java的Web应用程序发送的请求的WCF服务:

Encoding: UTF-8
Http-Method: POST
Content-Type: multipart/related; type="application/xop+xml"; boundary="uuid:83d3b2a6-5437-4366-bfb1-6f7c8b49add5"; start="<root.message@cxf.apache.org>"; start-info="application/soap+xml; action=\"urn:test:test1:ResponseInputMessage\""
Headers: {Accept=[*/*]}
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: <root.message@cxf.apache.org>

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><some_xml></soap:Body></soap:Envelope>
--uuid:83d3b2a6-5437-4366-bfb1-6f7c8b49add5--

我所拥有的是具有请求和响应类型的XSD文件。我生成了类并创建了基本服务。

服务合同

[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>

当我收到我的服务的入站消息时,它失败了404。

我尝试根据我的新服务的wsdl创建.net客户端来比较请求,但是Fiddler向我展示了4个与原始请求略有不同的请求:

请求1:

POST http://localhost/ResponseService.svc HTTP/1.1
MIME-Version: 1.0
Content-Type: multipart/related; type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:cc8ae94d-3397-4384-8460-738cf53f967b+id=1";start-info="application/soap+xml"
Host: localhost 
Content-Length: 1468
Expect: 100-continue
Accept-Encoding: gzip, deflate
Connection: Keep-Alive


--uuid:cc8ae94d-3397-4384-8460-738cf53f967b+id=1
Content-ID: <http://tempuri.org/0>
Content-Transfer-Encoding: 8bit
Content-Type: application/xop+xml;charset=utf-8;type="application/soap+xml"

<s:Envelope>...</s:Envelope>
--uuid:cc8ae94d-3397-4384-8460-738cf53f967b+id=1--

请求2:

POST http://localhost/ResponseService.svc HTTP/1.1
MIME-Version: 1.0
Content-Type: multipart/related; type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:cc8ae94d-3397-4384-8460-738cf53f967b+id=2";start-info="application/soap+xml"
Host: localhost
Content-Length: 1393
Expect: 100-continue
Accept-Encoding: gzip, deflate


--uuid:cc8ae94d-3397-4384-8460-738cf53f967b+id=2
Content-ID: <http://tempuri.org/0>
Content-Transfer-Encoding: 8bit
Content-Type: application/xop+xml;charset=utf-8;type="application/soap+xml"

<s:Envelope>...</s:Envelope>
--uuid:cc8ae94d-3397-4384-8460-738cf53f967b+id=2--

请求3:

POST http://localhost/ResponseService.svc HTTP/1.1
MIME-Version: 1.0
Content-Type: multipart/related; type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:cc8ae94d-3397-4384-8460-738cf53f967b+id=3";start-info="application/soap+xml"
Host: localhost
Content-Length: 6705
Expect: 100-continue
Accept-Encoding: gzip, deflate


--uuid:cc8ae94d-3397-4384-8460-738cf53f967b+id=3
Content-ID: <http://tempuri.org/0>
Content-Transfer-Encoding: 8bit
Content-Type: application/xop+xml;charset=utf-8;type="application/soap+xml"

<s:Envelope>...</s:Envelope>
--uuid:cc8ae94d-3397-4384-8460-738cf53f967b+id=3
Content-ID: <http://tempuri.org/1/636522286300409121>
Content-Transfer-Encoding: binary
Content-Type: application/octet-stream

<BINARY DATA>
--uuid:cc8ae94d-3397-4384-8460-738cf53f967b+id=3--

请求4:

POST http://localhost/ResponseService.svc HTTP/1.1
MIME-Version: 1.0
Content-Type: multipart/related; type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:cc8ae94d-3397-4384-8460-738cf53f967b+id=4";start-info="application/soap+xml"
VsDebuggerCausalityData: uIDPoy345YauwrpHkI3FNjB7gLEAAAAApHotH5ktEkaKGEpmm9Yap6yU6ZXr2SJLlqP656qr/dsACQAA
Host: localhost
Content-Length: 6565
Expect: 100-continue
Accept-Encoding: gzip, deflate


--uuid:cc8ae94d-3397-4384-8460-738cf53f967b+id=4
Content-ID: <http://tempuri.org/0>
Content-Transfer-Encoding: 8bit
Content-Type: application/xop+xml;charset=utf-8;type="application/soap+xml"

<s:Envelope>...</s:Envelope>
--uuid:cc8ae94d-3397-4384-8460-738cf53f967b+id=4
Content-ID: <http://tempuri.org/1/636522286300539469>
Content-Transfer-Encoding: binary
Content-Type: application/octet-stream

<BINARY DATA>
--uuid:cc8ae94d-3397-4384-8460-738cf53f967b+id=4--

有人可以解释请求如何映射到运营合同吗?我的服务定义中缺少什么?在原始请求中,至少有action=\"urn:test:test1:ResponseInputMessage\""

当您创建客户端时,您可以从wsdl自动生成所有内容是否存在基于请求生成服务的反向方法?

非常感谢任何帮助/文档!

0 个答案:

没有答案