我正在与我们的一位合作伙伴合作以整合我们的业务服务。我正在使用 WCF (.Net 3.5) 与合作伙伴 Web 服务进行通信。我认为合作伙伴 Web 服务是用 Java 编写的。
使用 SVC util 我生成了代理类。取而代之的是 DataContract 序列化程序,svcutil 使用了 xmlserializer。但合作伙伴提供的 WSDL 与 Web 服务响应 SOAP xml 不匹配。由于小伙伴对更改 wsdl 不感兴趣,所以我手动更改了下载的 WSDL 以匹配响应。该问题已得到修复。
现在我遇到了不同的问题。当我向 Web 服务发送请求时,它总是失败。然后我使用 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>
这是合作伙伴期望我们提供的示例 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>
<acd:SignonPswd>
<acd:CustId>
<acd:SPName>yourcompany.com</acd:SPName>
</acd:CustId>
</acd:SignonPswd>
</acd:SignonRq>
</stc1:ACORD>
</stc:input>
</stc:iL21stCentRq>
</soapenv:Body>
如果您比较这两个 XML,名称空间http://www.ACORD.org/standards/PC_Surety/ACORD1/xml/在合作伙伴 xml 中以“acd”为前缀,我们没有。合作伙伴希望我们以这种格式发送。
我认为Partner Xml 不符合标准。这真是伙伴问题。但是我别无选择,需要更改我这边的 Xml。
虽然我们可以自定义 WCF 服务中的序列化,但我不确定是否可以在此级别更改前缀。此外,我不确定 Partner Xml 是否遵循 XSD 的标准。
如果您可以指导修改 WCF 序列化以适应上述更改,我将不胜感激。