WCF SOAP调用HTTP报头的内容类型中缺少操作

本文关键字:类型 操作 调用 SOAP HTTP 报头 WCF | 更新日期: 2023-09-27 18:12:31

我已经调查了好几天了,为什么我的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>
    

  • 实例化和调用webservice的代码是:

    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内容类型:应用程序/soap + xml;utf - 8字符集=主持人:acccovwebservice.vecozo.nl内容长度:1216预计:100 -继续Accept-Encoding: gzip, deflate连接:维生

    & lt;销售:Header> http://schemas.vecozo.nl/VZ801802/v1/Controleer & lt;:消息id> urn: uuid: a492c393-a93b-43df-9f0e-4e3f7116f8a2<:消息id>& lt;: ReplyTo> http://www.w3.org/2005/08/addressing/anonymous & lt;/: ReplyTo> https://acccovwebservice.vecozo.nl/v1/VZ801802.svc & lt;/s: Header>& lt;销售:身体>& lt; Controleer xmlns = " http://schemas.vecozo.nl/VZ801802/v1 ">& lt;请求xmlns: b = " http://schemas.vecozo。问/VZ801802/v1/消息"xmlns:我= " http://www.w3.org/2001/XMLSchema-instance ">& lt; b: Zoekopdrachten xmlns: c = " http://schemas.vecozo.nl/VZ801802/v1/types ">& lt; c: Zoekopdracht>& lt; c: Volgnummer> 0 & lt;/c: Volgnummer>& lt; c: Geboortedatum> 1956 - 01 - 14 - & lt;/c: Geboortedatum>& lt; c: Peildatum> 2013 - 05 - 08 - & lt;/c: Peildatum>& lt; c: Bsn我:nil = " true "/>& lt; c: Verzekerdenummer> FB_60585我& lt; c:邮政编码:nil = " true "/>& lt; c: ReferentieZorgaanbieder我:nil = " true "/>& lt; c: Huisnummer我:nil = " true "/>& lt; c: Huisnummertoevoeging我:nil = " true "/>& lt;/c: Zoekopdracht>& lt;/b: Zoekopdrachten>& lt;/请求>& lt;/Controleer>& lt;/s:身体>& lt;/s:信封>

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

由于EndpointDispatcher的ContractFilter不匹配,带有"Action"的消息无法在接收端处理。这可能是由于合约不匹配(发送方和接收方之间的操作不匹配)或发送方和接收方之间的绑定/安全不匹配。检查发送方和接收方具有相同的契约和相同的绑定(包括安全要求,例如Message, Transport, None)。

供应商告诉我他在这条消息中看到两个问题:

  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.0BTW2我正在使用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); 
    }

WCF SOAP调用HTTP报头的内容类型中缺少操作

我想你的问题与:

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

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

我认为您对绑定的调整(添加自定义绑定)在某种程度上覆盖了wsHttpBinding的默认行为,这是将soap操作放入内容类型头值中。

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

编辑

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

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

var serviceBinding = new WSHttpBinding("vz801802Soap12");

或者设置Binding。MessageVersion属性

编辑

我不明白的是为什么你在代码中通过传递绑定来初始化客户端。您能否只创建客户机并在配置文件中传入客户机端点的名称?当你添加服务引用

时,应该没有理由在代码中创建东西,因为所有必要的东西都应该被visual studio放入配置中。