2

几天来,我一直在调查为什么我的 SOAP 请求根据我的供应商不正确,以及如何更改它。

我按照以下步骤创建了我的 SOAP 客户端:

  • 将服务引用添加到我的项目。服务的wsdl是:


    <?xml version="1.0" encoding="utf-8"?>
    <wsdl:definitions name="vz801802Service" targetNamespace="http://schemas.vecozo.nl/VZ801802/v1" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:tns="http://schemas.vecozo.nl/VZ801802/v1" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
     <wsp:Policy wsu:Id="vz801802Soap12_policy">
      <wsp:ExactlyOne>
       <wsp:All>
        <sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
         <wsp:Policy>
          <sp:TransportToken>
           <wsp:Policy>
            <sp:HttpsToken RequireClientCertificate="true"/>
           </wsp:Policy>
          </sp:TransportToken>
          <sp:AlgorithmSuite>
           <wsp:Policy>
            <sp:Basic256/>
           </wsp:Policy>
          </sp:AlgorithmSuite>
          <sp:Layout>
           <wsp:Policy>
            <sp:Strict/>
           </wsp:Policy>
          </sp:Layout>
         </wsp:Policy>
        </sp:TransportBinding>
       </wsp:All>
      </wsp:ExactlyOne>
     </wsp:Policy>
     <wsp:Policy wsu:Id="vz801802Soap11_policy">
      <wsp:ExactlyOne>
       <wsp:All>
        <sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
         <wsp:Policy>
          <sp:TransportToken>
           <wsp:Policy>
            <sp:HttpsToken RequireClientCertificate="true"/>
           </wsp:Policy>
          </sp:TransportToken>
          <sp:AlgorithmSuite>
           <wsp:Policy>
            <sp:Basic256/>
           </wsp:Policy>
          </sp:AlgorithmSuite>
          <sp:Layout>
           <wsp:Policy>
            <sp:Strict/>
           </wsp:Policy>
          </sp:Layout>
         </wsp:Policy>
        </sp:TransportBinding>
       </wsp:All>
      </wsp:ExactlyOne>
     </wsp:Policy>
     <wsdl:types>
      <xsd:schema targetNamespace="http://schemas.vecozo.nl/VZ801802/v1/Imports">
       <xsd:import schemaLocation="https://acccovwebservice.vecozo.nl/v1/VZ801802.svc?xsd=xsd0" namespace="http://schemas.vecozo.nl/VZ801802/v1"/>
       <xsd:import schemaLocation="https://acccovwebservice.vecozo.nl/v1/VZ801802.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
       <xsd:import schemaLocation="https://acccovwebservice.vecozo.nl/v1/VZ801802.svc?xsd=xsd2" namespace="http://schemas.vecozo.nl/VZ801802/v1/messages"/>
       <xsd:import schemaLocation="https://acccovwebservice.vecozo.nl/v1/VZ801802.svc?xsd=xsd3" namespace="http://schemas.vecozo.nl/VZ801802/v1/types"/>
      </xsd:schema>
     </wsdl:types>
     <wsdl:message name="vz801802Service_Controleer_InputMessage">
      <wsdl:part name="parameters" element="tns:Controleer"/>
     </wsdl:message>
     <wsdl:message name="vz801802Service_Controleer_OutputMessage">
      <wsdl:part name="parameters" element="tns:ControleerResponse"/>
     </wsdl:message>
     <wsdl:portType name="vz801802Service">
      <wsdl:operation name="Controleer">
       <wsdl:input wsaw:Action="http://schemas.vecozo.nl/VZ801802/v1/Controleer" message="tns:vz801802Service_Controleer_InputMessage"/>
       <wsdl:output wsaw:Action="http://schemas.vecozo.nl/VZ801802/v1/Controleer/reply" message="tns:vz801802Service_Controleer_OutputMessage"/>
      </wsdl:operation>
     </wsdl:portType>
     <wsdl:binding name="vz801802Soap12" type="tns:vz801802Service">
      <wsp:PolicyReference URI="#vz801802Soap12_policy"/>
      <soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
      <wsdl:operation name="Controleer">
       <soap12:operation soapAction="http://schemas.vecozo.nl/VZ801802/v1/Controleer" style="document"/>
       <wsdl:input>
        <soap12:body use="literal"/>
       </wsdl:input>
       <wsdl:output>
        <soap12:body use="literal"/>
       </wsdl:output>
      </wsdl:operation>
     </wsdl:binding>
     <wsdl:binding name="vz801802Soap11" type="tns:vz801802Service">
      <wsp:PolicyReference URI="#vz801802Soap11_policy"/>
      <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
      <wsdl:operation name="Controleer">
       <soap:operation soapAction="http://schemas.vecozo.nl/VZ801802/v1/Controleer" style="document"/>
       <wsdl:input>
        <soap:body use="literal"/>
       </wsdl:input>
       <wsdl:output>
        <soap:body use="literal"/>
       </wsdl:output>
      </wsdl:operation>
     </wsdl:binding>
     <wsdl:service name="vz801802Service">
      <wsdl:port name="vz801802Soap12" binding="tns:vz801802Soap12">
       <soap12:address location="https://acccovwebservice.vecozo.nl/v1/VZ801802.svc"/>
      </wsdl:port>
      <wsdl:port name="vz801802Soap11" binding="tns:vz801802Soap11">
       <soap:address location="https://acccovwebservice.vecozo.nl/v1/VZ801802.svc/soap11"/>
      </wsdl:port>
     </wsdl:service>
    </wsdl:definitions>

这为我创建了代理类。

  • 接下来我稍微调整了我的 app.config,强制它使用soap1.2(所以我删除了soap1.1 条目,因为我遇到了问题)

    <?xml version="1.0"?>
    <configuration>
        <system.serviceModel>
            <bindings>
                <customBinding>
                    <binding name="vz801802Soap12">
                        <textMessageEncoding messageVersion="Soap12" />
                        <httpsTransport requireClientCertificate="true" />
                    </binding>
                </customBinding>
            </bindings>
            <client>
                <endpoint address="https://acccovwebservice.vecozo.nl/v1/VZ801802.svc"
                    binding="customBinding" bindingConfiguration="vz801802Soap12"
                    contract="COV_VZ801802.vz801802Service" name="vz801802Soap12" />
            </client>
        </system.serviceModel>
    </configuration>
    

  • 实例化和调用 web 服务的代码是:

    WSHttpBinding serviceBinding = new WSHttpBinding(SecurityMode.Transport);
    serviceBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
    serviceBinding.ReceiveTimeout = new TimeSpan(0, 0, 120);
    EndpointAddress endpointAddress = new EndpointAddress(Bericht.Url); COV_VZ801802.vz801802ServiceClient VZ801_Client = new COV_VZ801802.vz801802ServiceClient(serviceBinding, endpointAddress);
    if (Bericht.Certificaat != null && Bericht.Certificaat != "") { X509Certificate2 x509_2 = new X509Certificate2(Bericht.Certificaat); VZ801_Client.ClientCredentials.ClientCertificate.Certificate = x509_2; }
    COV_VZ801802.ControleerRequestType VZ801_Request = new COV_VZ801802.ControleerRequestType();
    // Here I fill request with data
    COV_VZ801802.ControleerResponseType VZ801_Reponse = VZ801_Client.Controleer(VZ801_Request);

  • 使用 Fiddler 检查消息时,我看到以下内容:

    POST https://acccovwebservice.vecozo.nl/v1/VZ801802.svc HTTP/1.1
    Content-Type: application/soap+xml; charset=utf-8
    Host: acccovwebservice.vecozo.nl
    Content-Length: 1216
    Expect: 100-continue
    Accept-Encoding: gzip, deflate
    Connection: Keep-Alive

    <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"> <s:Header> <a:Action s:mustUnderstand="1">http://schemas.vecozo.nl/VZ801802/v1/Controleer</a:Action> <a:MessageID>urn:uuid:a492c393-a93b-43df-9f0e-4e3f7116f8a2</a:MessageID> <a:ReplyTo> <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address> </a:ReplyTo> <a:To s:mustUnderstand="1">https://acccovwebservice.vecozo.nl/v1/VZ801802.svc</a:To> </s:Header> <s:Body> <Controleer xmlns="http://schemas.vecozo.nl/VZ801802/v1"> <request xmlns:b="http://schemas.vecozo.nl/VZ801802/v1/messages" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <b:Zorgaanbieder i:nil="true" xmlns:c="http://schemas.vecozo.nl/VZ801802/v1/types"/> <b:Zoekopdrachten xmlns:c="http://schemas.vecozo.nl/VZ801802/v1/types"> <c:Zoekopdracht> <c:Volgnummer>0</c:Volgnummer> <c:Geboortedatum>1956-01-14</c:Geboortedatum> <c:Peildatum>2013-05-08</c:Peildatum> <c:Bsn i:nil="true"/> <c:Verzekerdenummer>FB_60585</c:Verzekerdenummer> <c:Postcode i:nil="true"/> <c:ReferentieZorgaanbieder i:nil="true"/> <c:Huisnummer i:nil="true"/> <c:Huisnummertoevoeging i:nil="true"/> </c:Zoekopdracht> </b:Zoekopdrachten> </request> </Controleer> </s:Body> </s:Envelope>

运行程序时,我得到一个异常,告诉我:

由于 EndpointDispatcher 的 ContractFilter 不匹配,接收方无法处理带有 Action '' 的消息。这可能是因为合约不匹配(发送方和接收方之间的操作不匹配)或发送方和接收方之间的绑定/安全不匹配。检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息、传输、无)。

供应商告诉我,他在此消息中看到了两个问题:

  1. 标头的内容类型中没有定义任何操作。内容类型应该是application/soap+xml;charset=UTF-8;action="http://schemas.vecozo.nl/VZ801802/v1/Controleer"
  2. MustUnderstand(在 Action 和 To 标记中)的两个值都应该是 0 而不是 1

我一直在搜索和搜索各种地方,尝试了自定义标题等,但我还没有找到解决这些问题的方法。

那里的任何人都可以帮助我吗???我很绝望,因为我需要在 6 月 1 日之前解决这个问题。

顺便说一句,我正在使用 .NET 4.0 BTW2 我正在使用 Visual Studio Express 2012 for Windows Desktop 来编辑我的项目

编辑:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] 
    [System.ServiceModel.ServiceContractAttribute(Namespace="schemas.vecozo.nl/VZ801802/v1";, ConfigurationName="COV_VZ801802.vz801802Service")] 
    public interface vz801802Service 
    { 
        [System.ServiceModel.OperationContractAttribute(Action="schemas.vecozo.nl/VZ801802/v1/Controleer";, ReplyAction="schemas.vecozo.nl/VZ801802/v1/Controleer/reply")] 
        SOAPLib.COV_VZ801802.ControleerResponseType Controleer(SOAPLib.COV_VZ801802.ControleerRequestType request); 
    }
4

1 回答 1

2

我认为你的问题与:

接下来我稍微调整了我的 app.config,强制它使用soap1.2

当您在代码中创建客户端时,您已经指定了 WSHttpBinding,默认情况下这将发送soap12 请求。

我认为您对绑定的调整(添加自定义绑定)以某种方式覆盖了 wsHttpBinding 的默认行为,即将肥皂操作放入内容类型标头值中。

如果您使用生成的配置文件而不进行调整会发生什么?

编辑

我的新理论是这样的——您在代码中创建客户端的方式导致 WCF 忽略配置文件中定义的绑定。

您应该通过传入配置文件中定义的客户端绑定的名称来创建绑定实例,例如:

var serviceBinding = new WSHttpBinding("vz801802Soap12");

要么在代码中设置Binding.MessageVersion 属性

编辑

那么我不明白的是为什么你通过传入绑定来初始化代码中的客户端。您可以只创建客户端并在配置文件中传递客户端端点的名称吗?没有理由开始在代码中创建东西,因为当您添加服务引用时,Visual Studio 应该已将所有必要的东西放入配置中

于 2013-05-08T14:29:45.127 回答