public static SoapDocument FromString(string soapString) { if (string.IsNullOrWhiteSpace(soapString)) { throw new ArgumentNullException(); } var soapDocument = new SoapDocument(); XDocument xmlDocument = XDocument.Parse(soapString); soapDocument.Namespaces = xmlDocument.Root.Attributes()?.Select(o => new SoapElement { Name = GetXElementFullName(o.Document.Root), Value = o.Value }).ToList(); XElement bodyElement = xmlDocument.Root.Elements().FirstOrDefault(o => !string.IsNullOrEmpty(o.Name.NamespaceName) && o.Name.LocalName == "Body"); XElement actionElement = bodyElement.Elements().FirstOrDefault(); soapDocument.Action = new SoapElement { Name = GetXElementFullName(actionElement) }; soapDocument.Action.Attrs = actionElement.Attributes()?.Select(o => new SoapElement { Name = GetXElementFullName(o), Value = o.Value }).ToList(); soapDocument.Args = actionElement.Elements()?.Select(o => { return(new SoapElement { Name = GetXElementFullName(o), Value = o.Value, Attrs = o.Attributes()?.Select(e => new SoapElement { Name = e.Name.LocalName, Value = e.Value }).ToList() }); }).ToList(); return(soapDocument); }
/// <summary> /// 请求Soap服务 /// </summary> /// <param name="url"></param> /// <param name="soapDocument"></param> /// <param name="timespanSeconds"></param> /// <returns></returns> public static async Task <SoapDocument> SoapRequestAsync(string url, SoapDocument soapDocument, double timespanSeconds = 30) { var rsp = await SoapRequestAsync(url, soapDocument.Action.LocalName, soapDocument.ToString()); return(SoapDocument.FromString(rsp)); }