简体   繁体   中英

How can I configure SOAP XML namespaces in web service client request?

I am having trouble calling a 3rd party web-service. I have not received a SOAP fault, but am not getting a valid resultset. A colleague of mine has written a client in RPG on the OS400 and it returns a valid resultset. When comparing the RAW request in Fiddler2 for both requests, the only glaring difference I noticed was that my c# client had SOAP xml elements with xmlns="" and his did not. Is it possible to remove said empty namespace declarations? Please see the referenced SOAP request below:

<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">
        <SendArchitectServiceRequest xmlns="archserver.xsd.dataflux.com">
            <serviceName xmlns="">AddressVerify.dmc</serviceName>
            <fieldDefinitions xmlns="">
                <fieldName>AddressLine_1</fieldName>
                <fieldType>STRING</fieldType>
                <fieldLength>255</fieldLength>
            </fieldDefinitions>
            <fieldDefinitions xmlns="">
                <fieldName>AddressLine_2</fieldName>
                <fieldType>STRING</fieldType>
                <fieldLength>255</fieldLength>
            </fieldDefinitions>
            <fieldDefinitions xmlns="">
                <fieldName>City_in</fieldName>
                <fieldType>STRING</fieldType>
                <fieldLength>255</fieldLength>
            </fieldDefinitions>
            <fieldDefinitions xmlns="">
                <fieldName>State_in</fieldName>
                <fieldType>STRING</fieldType>
                <fieldLength>255</fieldLength>
            </fieldDefinitions>
            <fieldDefinitions xmlns="">
                <fieldName>Zip</fieldName>
                <fieldType>STRING</fieldType>
                <fieldLength>255</fieldLength>
            </fieldDefinitions>
            <fieldDefinitions xmlns="">
                <fieldName>Country</fieldName>
                <fieldType>STRING</fieldType>
                <fieldLength>255</fieldLength>
            </fieldDefinitions>
            <dataRows xmlns="">
                <value>3485 W. Harmon Ave.</value>
                <value/>
                <value>Las Vegas</value>
                <value>NV</value>
                <value>89103</value>
                <value>United States</value>
                <reserved>0</reserved>
            </dataRows>
        </SendArchitectServiceRequest>
    </s:Body>
</s:Envelope>

Your proposed method seems like the easiest approach. One other approach would be to use SOAP extensions to modifiy the SOAP response, removing the empty xmlns attribute. You would modify the SoapClientMessage in the BeforeDeserialize stage of the SoapMessageStage .

由于我没有听到对第二个问题的任何评论或答案,因此我将接受我遇到的答案,该答案是更改System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)的自动生成的Reference.cs类XML元素声明System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM