[英]How to read soap response in c#?
Soap Respose as: 肥皂的处置方式为:
<?xml version="1.0" encoding="utf-8" ?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<LoginResponse xmlns="http://example.com/SystemIntegration">
<FirstName>@FirstName</FirstName>
<LastName>@LastName</LastName>
</LoginResponse>
</soap:Body>
</soap:Envelope>
I'm trying to read it as: 我正在尝试将其读取为:
XDocument doc = XDocument.Parse(strReturnStatus);
List<XElement> result = doc.Elements("LoginResponse").ToList();
for (int intc = 0; intc <= result.Count - 1; intc++)
{
strResponseCode = result[intc].Element("FirstName").Value.ToString();
strResponseText = result[intc].Element("LastName").Value.ToString();
}
But it returning null
result. 但是它返回
null
结果。
How to read above respose in asp.net c#
?? 如何在
asp.net c#
阅读以上内容?
The easiest thing is to create a proxy class for your service. 最简单的方法是为您的服务创建代理类。
You can do that using the 'Add Service Reference' option in Visual Studi o. 您可以使用Visual Studi o中的“添加服务引用”选项来实现 。 Enter the URL of the service, and Visual Studio will generate the source code for you.
输入服务的URL,Visual Studio将为您生成源代码。
From that point you can access the service using C# code. 从那时起,您可以使用C#代码访问该服务。 No need to manually extract the payload of the SOAP message.
无需手动提取SOAP消息的有效负载。
Note if you are the implementator of the service: ASMX webservices are deprecated for a long time already. 请注意,如果您是该服务的实现者:长时间不建议使用ASMX Web服务。 If you can, use WCF.
如果可以,请使用WCF。
在XDocumentobject中使用Descendants()方法浏览XML节点以获取元素,您可以按照本文中提供的步骤使用C#解析SOAP Response
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.