如何反序列化带有前缀的soap请求

时间:2018-08-02 18:24:43

标签: xml web-services soap

我已经在Internet上搜索了,但没有得到答案。我已经浏览了Rick Strahl的网络日志WCF中的Custom-Message-Formatting-in-WCF,但没有帮助。

我的问题与此问题How to deserialize a soap request with a namespace prefix?类似,但是我正在使用Web服务。这两个答案没有提供解决方案。

第一个请求在ASS中返回null,而第二个工作正常。唯一的区别是附加到请求元素名称ASS的ns1前缀。第一个请求来自我无法更改的外部来源。我该如何处理这样的请求?

    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org  /soap/envelope/" xmlns:ns1="http://xxx.xxxx.com">
    <SOAP-ENV:Body>
    <ns1:ASS>
    <MRequest>
    <RefNo>34</RefNo>
    <mobileNo></mobileNo>
    <mobileName></mobileName>
    </MRequest>
    </ns1:ASS>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>


    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://xxx.xxxx.com">
    <SOAP-ENV:Body>
    <ASS>
   <MRequest>
   <RefNo>34</RefNo>
   <mobileNo></mobileNo>
   <mobileName></mobileName>
   </MRequest>
   <ASS>
   </SOAP-ENV:Body>
   </SOAP-ENV:Envelope>

这是网络方法

[WebMethod]
[return: XmlElement(ElementName = "return")]
[XmlRootForcePrefix(Prefix ="ns1", Priority =1)] // This adds the ns1 prefix to ASS response element
[SoapDocumentMethod(RequestElementName = "ASS", RequestNamespace = "", ResponseNamespace = "http://xxx.xxxx.com")]
 public ASSResponse ASS(ASSRequest assrequest)
        {
            do something;
            return ASSResponse;

        }

如果我向该函数发送第一个请求,则assrequest返回null,但如果我发送第二个请求,则assrequest获取参数。响应参数必须按字母顺序列出,并且不进行编码。

在为响应元素名称添加值之后,ns1在反序列化soap请求中,并在所有元素上附加了前缀,如下所示。

                                            34                                                      

如何从参数中删除ns1前缀并将其单独留在ASS节点中?

0 个答案:

没有答案
相关问题