前缀 SOAP XML 代替直接命名空间 [英] Prefix SOAP XML Instead direct namespace

查看:25
本文介绍了前缀 SOAP XML 代替直接命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与我们的一位合作伙伴合作以整合我们的业务服务.我正在使用 WCF (.Net 3.5) 与合作伙伴 Web 服务进行通信.我认为合作伙伴 Web 服务是用 Java 编写的.

I am working with one of our partner to integrate our business services. I am using WCF (.Net 3.5) to communicate with partner web service. I think partner web service is written in Java.

使用 SVC util 我生成了代理类.取而代之的是 DataContract 序列化程序,svcutil 使用了 xmlserializer.但合作伙伴提供的 WSDL 与 Web 服务响应 SOAP xml 不匹配.由于小伙伴对更改 wsdl 不感兴趣,所以我手动更改了下载的 WSDL 以匹配响应.该问题已得到修复.

Using SVC util I generated proxy class. Instead DataContract serializer, svcutil used xmlserializer. But WSDL provided by partner and the web service response SOAP xml does not match. Since the partner not interested in changing the wsdl, I have changed downloaded WSDL manually to match the response. That issue has been fixed.

现在我遇到了不同的问题.当我向 Web 服务发送请求时,它总是失败.然后我使用 fiddler 将 SOAP 请求转发给合作伙伴.合作伙伴表示,请求发送的 xml 命名空间并未针对他们的系统进行验证.他们还回复了示例 SOAP 请求.

Now I am running into different problem. When I send a request to the web service, it always failed. Then I used fiddler to get the SOAP request forwarded to the partner. Partner said the xml namespaces sent by the request does not validate against their systems. They also replied with sample SOAP request.

通过比较这两个请求,命名空间看起来是正确的.但是合作伙伴 xml 使用前缀来定义命名空间,并且元素都带有前缀.而我们这边的 xml 没有前缀,而是直接在父元素中使用命名空间.

By comparing the both requests, the namespaces looks correct. But partner xml uses the prefixes to define the namespaces and elements are prefixed. Whereas xml on our side does not have prefixes instead used the namespaces directly in the parent element.

这是我们发送的 XML

Here is the XML that we sent

<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

Here is the Sample XML that partner expected from us

<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"为前缀.合作伙伴希望我们以这种格式发送.

If you compare the both XML, the namespace http://www.ACORD.org/standards/PC_Surety/ACORD1/xml/ is prefixed by "acd" in partner xml our does not. Partner wanted us to send in that format.

我认为 Partner Xml 不符合标准.这真是伙伴问题.但我别无选择,需要更改我这边的 Xml.

I think Partner Xml does not follow the standards. This really partner problem. But I had no option left and required to change the Xml on my side.

虽然我们可以在 WCF 服务中自定义序列化,但我不确定是否可以在此级别更改前缀.此外,我不确定 Partner Xml 是否遵循 XSD 的标准.

Though we could customize the serialization in WCF service, I am not sure it is possible to change prefix at this level. Moreover I am not sure that the Partner Xml following the standards of XSD.

如果您能指导修改 WCF 序列化以适应上述更改,我将不胜感激.

If you could guide to modify the WCF serialization to accommodate the above said changes, I would appreciate it.

推荐答案

我修复了 SVC Util 生成的代理类.我添加了一个发出前缀的新属性.例如在类 SignonRq 中,我添加了以下属性.用前缀 acd 序列化 XML

I fixed proxy class generated by SVC Util. I added a new property that emit the prefix. For example in class SignonRq, I added the following property. That serialized the XML with prefix acd

        [XmlNamespaceDeclarations()]
    public XmlSerializerNamespaces xmlsn
    {
        get
        {
            XmlSerializerNamespaces xsn = new XmlSerializerNamespaces();
            xsn.Add("acd", "http://www.ACORD.org/standards/PC_Surety/ACORD1/xml/");
            return xsn;
        }
        set
        {
            //Just provide an empty setter. 
        }
    }

例如 ACORD 类,我添加了以下属性.这序列化了带有前缀 stc1 的 XML.

For example class ACORD, I added the following property. That serialized the XML with prefix stc1.

        [XmlNamespaceDeclarations()]
    public XmlSerializerNamespaces xmlsn
    {
        get
        {
            XmlSerializerNamespaces xsn = new XmlSerializerNamespaces();
            xsn.Add("stc1", "http://schemas.WebServiceProvider.com/us/ileads/types/Servicing");
            return xsn;
        }
        set
        {
            //Just provide an empty setter. 
        }
    }

这篇关于前缀 SOAP XML 代替直接命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆