我有一个生成请求的WCF SOAP客户端.这被服务器拒绝为无效请求.我已经使用SOAPUI将其追溯到命名空间,但无法弄清楚如何让客户端生成所需的结果.
客户端是从wsdl生成的Web服务引用,并生成以下SOAP消息;
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header></s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<createShipmentRequest xmlns="http://www.royalmailgroup.com/api/ship/V2">
<integrationHeader>
<dateTime xmlns="http://www.royalmailgroup.com/integration/core/V1">2015-07-23</dateTime>
<version xmlns="http://www.royalmailgroup.com/integration/core/V1">2</version>
<identification xmlns="http://www.royalmailgroup.com/integration/core/V1">
<applicationId>some random number</applicationId>
<transactionId>some reference number</transactionId>
</identification>
</integrationHeader>
</createShipmentRequest>
</s:Body>
</s:Envelope>
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,名称空间正在各个元素上输出......
我的工作示例在SOAP Envelope中定义了名称空间;
<s:Envelope xmlns:v2="http://www.royalmailgroup.com/api/ship/V2" xmlns:v1="http://www.royalmailgroup.com/integration/core/V1" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header></s:Header>
<s:Body>
<v2:createShipmentRequest>
<v2:integrationHeader>
<v1:dateTime>2015-07-23</v1:dateTime>
<v1:version>2</v1:version>
<v1:identification>
<v1:applicationId>some random number</v1:applicationId>
<v1:transactionId>some reference number</v1:transactionId>
</v1:identification>
</v2:integrationHeader>
</v2:createShipmentRequest>
</s:Body>
</s:Envelope>
Run Code Online (Sandbox Code Playgroud)
根据我的理解,这不应该有所作为,但服务器只是拒绝请求.在SOAPUI中修改我生成的请求之后,它肯定会导致问题,那么我如何将两个命名空间定义v1和v2移动到SOAP Envelope,然后让正确的元素使用正确的前缀?
我的客户端使用以下功能启动;
private shippingAPIPortTypeClient GetProxy() {
BasicHttpBinding myBinding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
shippingClient = new shippingAPIPortTypeClient(myBinding, new EndpointAddress(new Uri(shippingClientSandboxEndpoint), EndpointIdentity.CreateDnsIdentity("api.royalmail.com"), new AddressHeaderCollection())); …Run Code Online (Sandbox Code Playgroud) 我正在与我们的一位合作伙伴合作整合我们的业务服务。我正在使用 WCF (.Net 3.5) 与合作伙伴 Web 服务进行通信。我认为合作伙伴 Web 服务是用 Java 编写的。
使用 SVC util 我生成了代理类。svcutil 使用 xmlserializer 代替 DataContract 序列化器。但合作伙伴提供的 WSDL 与 Web 服务响应 SOAP xml 不匹配。由于合作伙伴对更改 wsdl 不感兴趣,因此我手动更改了下载的 WSDL 以匹配响应。该问题已得到解决。
现在我遇到了不同的问题。当我向网络服务发送请求时,它总是失败。然后我使用 fiddler 将 SOAP 请求转发给合作伙伴。合作伙伴表示,请求发送的 xml 命名空间未针对其系统进行验证。他们还回复了示例 SOAP 请求。
通过比较这两个请求,命名空间看起来是正确的。但是合作伙伴 xml 使用前缀来定义命名空间,并且元素都带有前缀。而我们这边的 xml 没有前缀,而是直接在父元素中使用命名空间。
这是我们发送的 XML
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<iL21stCentRq xmlns="http://schemas.WebServiceProvider.com/us/ileads/messages/Servicing">
<ACORD xmlns="http://schemas.WebServiceProvider.com/us/ileads/types/Servicing">
<SignonRq xmlns="http://www.ACORD.org/standards/PC_Surety/ACORD1/xml/">
<SignonPswd>
<CustId>
<SPName>111</SPName>
</CustId>
</SignonPswd>
</SignonRq>
</ACORD>
</iL21stCentRq>
</s:Body>
Run Code Online (Sandbox Code Playgroud)
这是合作伙伴期望我们提供的示例 XML
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:stc="http://schemas.WebServiceProvider.com/us/ileads/messages/Servicing" xmlns:stc1="http://schemas.WebServiceProvider.com/us/ileads/types/Servicing" xmlns:acd="http://www.ACORD.org/standards/PC_Surety/ACORD1/xml/">
<soapenv:Header/>
<soapenv:Body>
<stc:iL21stCentRq>
<stc:input>
<stc1:ACORD>
<acd:SignonRq> …Run Code Online (Sandbox Code Playgroud)