1

我尝试使用 RestClient 从 soapenv 获取会话 ID,但我得到的值为 0 或 -1。

这是我的代码

var client = new RestClient(url);
        client.Authenticator = new HttpBasicAuthenticator(name, pwd);
        var request = new RestRequest("/{sessionID}",Method.GET);

        var response = client.Get(request);
        var content = response.Content; // Raw content as string
        Console.WriteLine(response.ContentLength);

我的 Soapenv 看起来像这样

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v7="urn://oracle.bi.webservices/v7">
   <soapenv:Header/>
   <soapenv:Body>
      <v7:logon>
         <v7:name>pxxxx</v7:name>
         <v7:password>Pxxxx</v7:password>
      </v7:logon>
   </soapenv:Body>
</soapenv:Envelope>

我正在尝试获取看起来像这样的会话 ID (9insv92nke9lig83bqd5pu5tqt7kp8u0toe9l)

<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" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:sawsoap="urn://oracle.bi.webservices/v7">
   <soap:Body>
      <sawsoap:logonResult>
         <sawsoap:sessionID xsi:type="xsd:string">9insv92nke9lig83bqd5pu5tqt7kp8u0toe9l</sawsoap:sessionID>
      </sawsoap:logonResult>
   </soap:Body>
</soap:Envelope>

无法弄清楚如何获取会话 ID。任何人都可以帮忙吗?

4

1 回答 1

0

尝试以下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.IO;
namespace ConsoleApp1
{
    class Program
    {
        const string FILENAME = @"c:\Temp\Test.xml";
        static void Main(string[] args)
        {
            string content = File.ReadAllText(FILENAME);
            XDocument doc = XDocument.Parse(content);
            XElement xSessionID = doc.Descendants().Where(x => x.Name.LocalName == "sessionID").FirstOrDefault();
            string sessionID = (string)xSessionID;

        }
    }
}
于 2021-09-04T15:35:09.033 回答