繁体   English   中英

使用C#消费SOAP / SSO

[英]Consume SOAP/SSO using C#

使用C#来使用WSDL SOAP / SSO的最简单方法是什么?

这是第三方系统,我得到以下答复:

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <RetornaEstadosPorMarcaResponse xmlns="http://WebService-MultiLogin-2013/">
      <RetornaEstadosPorMarcaResult>
        <EstadosMDL>
          <ID>int</ID>
          <Nome>string</Nome>
          <Sigla>string</Sigla>
        </EstadosMDL>
        <EstadosMDL>
          <ID>int</ID>
          <Nome>string</Nome>
          <Sigla>string</Sigla>
        </EstadosMDL>
      </RetornaEstadosPorMarcaResult>
    </RetornaEstadosPorMarcaResponse>
  </soap:Body>
</soap:Envelope>

这就是我所说的:

public AdminMaster.RetornaEstadosPorMarca.Estados ssoEstados = new AdminMaster.RetornaEstadosPorMarca.Estados();

ssoEstados.RetornaEstadosPorMarca(Library.Configuracoes.ChaveSSO, Convert.ToInt16(Library.Configuracoes.Marca));

我已经尝试过将其接收为字符串并将其格式化为XML格式,但由于<soap:Body><soap:Envelope>而无法正常工作,我收到了错误消息,因为在名称,我认为这不是最简单的方法。

那么,如何从响应中访问信息? 还有另一种方法吗?

编辑:

经过几个小时的测试,我终于找到了问题,“我的” SOAP也给了我一个类来创建一个对象来接收响应,我只需要使用它:

//Here i have the object with the methods
private Library.ssoEstados.Estados objEstadosSSO = new Library.ssoEstados.Estados();

//Here i have the object to receive the response    
private Library.ssoEstados.EstadosMDL[] objEstadosMDL;

不仅仅是读取我想要的值并将其发送到我自己的对象。

XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(inputXml);
XmlNamespaceManager namespaces = new XmlNamespaceManager(xDoc.NameTable);
namespaces.AddNamespace("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
namespaces.AddNamespace("ns2", "http://tempuri.org/");
XmlNode accountNode = xDoc.SelectSingleNode("/soapenv:Envelope/soapenv:Body/ns2:RetornaEstadosPorMarcaResponse/RetornaEstadosPorMarcaResult", namespaces);
XmlNode xnlAccount = accountNode.ChildNodes[0];
if (xnlAccount != null)
{
    XmlDocument xAccount = new XmlDocument();
    xAccount.LoadXml(xnlAccount.InnerText);
}

inputXml是包含您的响应xml的字符串。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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