gpt4 book ai didi

c# - WCF SOAP 调用 HTTP header 的内容类型中缺少操作

转载 作者:太空宇宙 更新时间:2023-11-03 11:04:24 27 4
gpt4 key购买 nike

几天来,我一直在调查为什么我的 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);<br/>
    EndpointAddress endpointAddress = new EndpointAddress(Bericht.Url);
    COV_VZ801802.vz801802ServiceClient VZ801_Client = new COV_VZ801802.vz801802ServiceClient(serviceBinding, endpointAddress);<br/>
    if (Bericht.Certificaat != null && Bericht.Certificaat != "")
    {
    X509Certificate2 x509_2 = new X509Certificate2(Bericht.Certificaat);
    VZ801_Client.ClientCredentials.ClientCertificate.Certificate = x509_2;
    }<br/>
    COV_VZ801802.ControleerRequestType VZ801_Request = new COV_VZ801802.ControleerRequestType();<br/>
    // Here I fill request with data<br/>
    COV_VZ801802.ControleerResponseType VZ801_Reponse = VZ801_Client.Controleer(VZ801_Request);

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

    POST <code>https://acccovwebservice.vecozo.nl/v1/VZ801802.svc</code> 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<p></p>

    <p><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"><code>http://schemas.vecozo.nl/VZ801802/v1/Controleer</code></a:Action>
    <a:MessageID>urn:uuid:a492c393-a93b-43df-9f0e-4e3f7116f8a2</a:MessageID>
    <a:ReplyTo>
    <a:Address><code>http://www.w3.org/2005/08/addressing/anonymous</code></a:Address>
    </a:ReplyTo>
    <a:To s:mustUnderstand="1"><code>https://acccovwebservice.vecozo.nl/v1/VZ801802.svc</code></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></p>



运行程序时,出现异常,告诉我:

The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).

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

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

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

有人可以帮我解决这个问题吗???我非常绝望,因为我需要在 6 月 1 日之前解决这个问题。

顺便说一句,我正在使用 .NET 4.0顺便说一句,我正在使用 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);
}

最佳答案

我认为你的问题与:

Next I tweaked my app.config a little, to force it to use soap1.2

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

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

如果您在不进行调整的情况下使用生成的配置文件会怎样?

编辑

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

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

var serviceBinding = new WSHttpBinding("vz801802Soap12");

或者设置Binding.MessageVersion property也在代码中。

编辑

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

关于c# - WCF SOAP 调用 HTTP header 的内容类型中缺少操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16439191/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com