使用SSO / SOAP响应

时间:2014-05-26 15:55:00

标签: c# asp.net soap single-sign-on

我有这个SSO / SOAP WebService,我需要使用一些信息而且我没有使用C#/ ASP.NET所以我不知道如何获得对可用对象的响应。

这是SOAP的回归

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

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

我有一个对象,我想填充返回:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Collections;

namespace Library
{
    public class Estados
    {
        //Here i'm creating the object
        private AdminMaster.RetornaEstadosPorMarca.Estados ssoEstados = new AdminMaster.RetornaEstadosPorMarca.Estados();

        public List<Estados> lstEstado = new List<Estados>();

        #region Propriedades
            public int ID
            {
                get;
                set;
            }
            public string Nome
            {
                get;
                set;
            }
            public string Sigla
            {
                get;
                set;
            }
        #endregion

        #region Métodos
            /// <summary>
            /// Lista Todos os Estados
            /// </summary>
            /// <returns></returns>
            public void Listar(Library.Estados objEstados)
            {
                //Here i'm calling the function that will return me the States(response)
                ssoEstados.RetornaEstadosPorMarca(Library.Configuracoes.ChaveSSO, Library.Configuracoes.Marca);
            }
        #endregion
    }
}

现在,如何读取/使用该响应并将其放入我的Estados对象中以用于项目?

修改

我试过了:

StringBuilder output = new StringBuilder();

// Create an XmlReader
using (XmlReader reader = XmlReader.Create(new StringReader(respSSO)))
{
    reader.ReadToFollowing("EstadosMDL");
    reader.MoveToFirstAttribute();
    string genre = reader.Value;

    return genre;
 }

并收到此错误:

[NullReferenceException: Object reference not set to an instance of an object.]
   Library.Configuracoes.get_ChaveSSO() +95
   Library.Estados.Listar() +89
   AdminMaster.SiteMaster.ListaEstados() +113
   AdminMaster.SiteMaster.Page_Load(Object sender, EventArgs e) +50
   System.Web.UI.Control.LoadRecursive() +70
   System.Web.UI.Control.LoadRecursive() +189
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3177

1 个答案:

答案 0 :(得分:1)

通常,您从SOAP请求返回的响应将是XML格式的字符串。然后,您将获取XmlReader并将字符串解析为XML元素,并在解析时处理它们。

XmlReader:msdn.microsoft.com/en-us/library/cc189056(v=vs.95).aspx

此示例显示如何通过交换机解析每个节点:

// Parse the file and display each of the nodes.
        while (reader.Read())
        {
            switch (reader.NodeType)
            {
                case XmlNodeType.Element:
                    writer.WriteStartElement(reader.Name);
                    break;
                case XmlNodeType.Text:
                    writer.WriteString(reader.Value);
                    break;
                case XmlNodeType.XmlDeclaration:
                case XmlNodeType.ProcessingInstruction:
                    writer.WriteProcessingInstruction(reader.Name, reader.Value);
                    break;
                case XmlNodeType.Comment:
                    writer.WriteComment(reader.Value);
                    break;
                case XmlNodeType.EndElement:
                    writer.WriteFullEndElement();
                    break;
            }
        }