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

查看:356
本文介绍了前缀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服务发送请求时,它总是失败.然后,我使用提琴手将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天全站免登陆