根据我的供应商,我一直在调查为什么我的SOAP请求不正确,以及我如何更改它。
我按照以下步骤创建了我的SOAP客户端:
<?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>
实例化和调用网络服务的代码是:
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>
https://acccovwebservice.vecozo.nl/v1/VZ801802.svc
http://schemas.vecozo.nl/VZ801802/v1/Controleer
http://www.w3.org/2005/08/addressing/anonymous
运行程序时,我得到一个例外,告诉我:
由于EndpointDispatcher上的ContractFilter不匹配,无法在接收方处理带有Action''的消息。这可能是由于合同不匹配(发送方与接收方之间的操作不匹配)或发送方与接收方之间的绑定/安全性不匹配。检查发件人和收件人是否具有相同的合同和相同的约束(包括安全要求,例如邮件,传输,无)。
供应商告诉我他在这条消息中看到了两个问题:
https://acccovwebservice.vecozo.nl/v1/VZ801802.svc
我一直在搜索和搜索所有类型的地方,尝试自定义标题等等,但我找不到解决这些问题的方法。
那里的任何人都可以帮我这个???我非常绝望,因为我需要在6月1日之前解决这个问题。
BTW我使用的是.NET 4.0 BTW2我正在使用Visual Studio Express 2012 for Windows Desktop来编辑我的项目
编辑:
答案 0 :(得分:2)
我认为你的问题与:
有关接下来,我稍微调整了我的app.config,强制它使用soap1.2
在代码中创建客户端时,您已经在指定WSHttpBinding,默认情况下会发送soap12请求。
我认为你对绑定的调整(添加自定义绑定)会以某种方式覆盖wsHttpBinding的默认行为,即将soap操作放入content-type标头值。
如果在不调整的情况下使用生成的配置文件会发生什么?
修改强>
我的新理论是这样的 - 您在代码中创建客户端的方式导致WCF忽略配置文件中定义的绑定。
您应该通过传入配置文件中定义的客户端绑定的名称来创建绑定实例,例如:
var serviceBinding = new WSHttpBinding("vz801802Soap12");
也可以在代码中设置Binding.MessageVersion property。
修改强>
我不明白的是,为什么要通过传递绑定来初始化代码中的客户端。你能创建客户端并在配置文件中传入客户端端点的名称吗?应该没有理由开始在代码中创建内容,因为当您添加服务引用时,visual studio应该将所有必要的东西放入配置中