C# WCF SOAP调用HTTP头的内容类型中缺少操作
根据我的供应商,我已经调查了几天为什么我的SOAP请求不正确,以及如何更改它 我按照以下步骤创建SOAP客户端:C# WCF SOAP调用HTTP头的内容类型中缺少操作,c#,wcf,soap,C#,Wcf,Soap,根据我的供应商,我已经调查了几天为什么我的SOAP请求不正确,以及如何更改它 我按照以下步骤创建SOAP客户端: 已将服务引用添加到我的项目中。服务的wsdl是: 运行程序时,我遇到一个异常,告诉我: 由于EndpointDispatcher上的ContractFilter不匹配,无法在接收器上处理具有操作“”的消息。这可能是因为合同不匹配(发送方和接收方之间的操作不匹配)或发送方和接收方之间的绑定/安全不匹配。检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息、传输
- 已将服务引用添加到我的项目中。服务的wsdl是:
application/soap+xml;字符集=UTF-8;行动=”http://schemas.vecozo.nl/VZ801802/v1/Controleer“
[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);
}
我认为你的问题在于: 接下来,我稍微调整了app.config,强制它使用soap1.2 在代码中创建客户机时,您已经指定了WSHttpBinding,默认情况下,这将发送soap12请求 我认为您对绑定的调整(添加自定义绑定)在某种程度上覆盖了wsHttpBinding的默认行为,即将soap操作放入内容类型头值中 如果使用生成的配置文件而不进行调整,会发生什么情况 编辑 我的新理论是——在代码中创建客户机的方式导致WCF忽略配置文件中定义的绑定 您应该通过传入配置文件中定义的客户端绑定的名称来创建绑定实例,例如:
var serviceBinding = new WSHttpBinding("vz801802Soap12");
要么这样,要么在代码中设置
编辑
我不明白的是,为什么要在代码中通过传递绑定来初始化客户机。您可以创建客户端并在配置文件中传入客户端端点的名称吗?应该没有理由开始在代码中创建内容,因为在添加服务引用时,visual studio应该已将所有必要的内容放入配置中请共享已断开的操作合同的合同定义。您是指代理代码:[System.CodeDom.Compiler.GeneratedCodeAttribute(“System.ServiceModel”),“4.0.0.0”)][System.ServiceModel.ServiceContractAttribute(名称空间=”,ConfigurationName=“COV_VZ801802.vz801802Service”)]公共接口vz801802Service{[System.ServiceModel.OperationContractAttribute(Action=”,ReplyAction=“SOAPLib.COV_VZ801802.ControleerResponseType Controleer(SOAPLib.COV_VZ801802.ControleerRequestType请求);}“1.标头的内容类型中未定义任何操作…”刚看了我的WCF 4应用程序,它确实可以在没有这些信息的情况下运行。但为什么我的供应商告诉我它丢失了?我从搜索SOAP12中了解到的信息也应该自动生成它?内容类型中的操作不是强制性的。因此,如果你的供应商的服务依赖于req中存在的信息,那么它就不符合标准uest.你能发布重新生成的应用程序配置吗?当尝试客户端绑定时,我得到错误:在配置元素集合中找不到与键“vz801802Soap12”匹配的元素。当请求我的wsHttpBinding的MessageVersion时,它给出了带地址10的met SAOP12,因此在我看来是正确的。我不明白的是为什么要通过传递绑定在代码中初始化客户端。您可以创建客户端并在配置文件中传递客户端终结点的名称吗?应该没有理由开始在代码中创建内容,因为在添加服务引用时,visual studio应已将所有必要的内容放入配置中。谢谢!!!Th这就是解决方案。很明显,我缺乏SOAP知识,所以我开始用我的方式编程。阿甘,非常感谢! 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); 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>
[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);
}
var serviceBinding = new WSHttpBinding("vz801802Soap12");