Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
829 views
in Technique[技术] by (71.8m points)

wcf - Prefix SOAP XML Instead direct namespace

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.

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.

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.

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.

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>

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>

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.

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.

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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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. 
        }
    }

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. 
        }
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...