在C#中解析和查询SOAP [英] Parse and query SOAP in C#

查看:211
本文介绍了在C#中解析和查询SOAP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解析大量命名空间的SOAP消息(也可以在此处找到源):

I am trying to parse a heavily namespaced SOAP message (source can be found also here):

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <soapenv:Header>
  <ns1:TransactionID soapenv:mustUnderstand="1" xsi:type="xsd:string" xmlns:ns1="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-2">0a00f556419041c08d8479fbaad02a3c</ns1:TransactionID>
 </soapenv:Header>
 <soapenv:Body>
  <SubmitRsp xmlns="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-2">
   <MM7Version>5.3.0</MM7Version>
   <Status>
    <StatusCode xsi:type="ns2:responseStatusType_StatusCode" xmlns:ns2="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-2" xmlns="">1000</StatusCode>
    <StatusText xsi:type="ns3:statusTextType" xmlns:ns3="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-2" xmlns="">Success</StatusText>
   </Status>
   <MessageID>B08CF7B847DAD89C752334BDEBB69B5B</MessageID>
  </SubmitRsp>
 </soapenv:Body>
</soapenv:Envelope>

仅就上下文而言,这是对 MM7 Submit 消息的响应.

Just for the context, this is a response of MM7 Submit message.

如何获取以下值:

TransactionID,StatusCode,StatusText,MessageID

TransactionID, StatusCode, StatusText, MessageID

我尝试使用Linq-Xml,但是当查询中包含"soapenv:Body"之类的值时却没有运气.

I tried Linq-Xml but no luck when the query includes a value like "soapenv:Body".

推荐答案

如果要使用命名空间构建XName,则需要从XNamespace加上字符串(例如

If you're trying to build an XName with a namespace you need to build it from an XNamespace plus a string, e.g.

XNamespace soapenv = "http://schemas.xmlsoap.org/soap/envelope/";
XName body = soapenv + "Body";

然后,当将XName"body"与Linq-to-XML一起使用时,它将与文档中的<soapenv:Body>元素匹配.

Then when you use the XName "body" with Linq-to-XML it will match the <soapenv:Body> element in your document.

您可以做类似的事情以允许使用命名空间构建其他元素的名称.

You can do similar things to allow building the names of other elements with namespaces.

这篇关于在C#中解析和查询SOAP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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