0

I am creating a simple console application to get a response from a cloud web service. I am able to get the response payload in xml format however I am finding it difficult to read the XML tags and get the value from a tag.

Below is the response I am receiving,

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing">
   <env:Header>
      <wsa:Action>http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService//FlowActionsService/getFlowTaskInstanceStatusResponse</wsa:Action>
      <wsa:MessageID>urn:uuid:2a2436b3-c018-4ef7-93b6-bd8b82a82041</wsa:MessageID>
   </env:Header>
   <env:Body>
      <ns0:getFlowTaskInstanceStatusResponse xmlns:ns0="http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService/types/">
         <result xmlns="http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService/types/">COMPLETED</result>
      </ns0:getFlowTaskInstanceStatusResponse>
   </env:Body>
</env:Envelope>

I am trying to read the text withing the result tag. Could some one help me with the code in C#. Do let me know if further information is needed.

  • 1
    It looks like web service wsdl that [can be converted](https://stackoverflow.com/questions/2772708/how-to-make-a-soap-wsdl-client-in-c) to the C# source code – oleksa Jan 05 '20 at 10:40
  • Does this answer your question? [How to make a SOAP/WSDL client in C#?](https://stackoverflow.com/questions/2772708/how-to-make-a-soap-wsdl-client-in-c) – oleksa Jan 05 '20 at 10:41

2 Answers2

0

sample c# class:

[XmlRoot(ElementName="Header", Namespace="http://schemas.xmlsoap.org/soap/envelope/")]
public class Header {
    [XmlElement(ElementName="Action", Namespace="http://www.w3.org/2005/08/addressing")]
    public string Action { get; set; }
    [XmlElement(ElementName="MessageID", Namespace="http://www.w3.org/2005/08/addressing")]
    public string MessageID { get; set; }
}

[XmlRoot(ElementName="result", Namespace="http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService/types/")]
public class Result {
    [XmlAttribute(AttributeName="xmlns")]
    public string Xmlns { get; set; }
    [XmlText]
    public string Text { get; set; }
}

[XmlRoot(ElementName="getFlowTaskInstanceStatusResponse", Namespace="http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService/types/")]
public class GetFlowTaskInstanceStatusResponse {
    [XmlElement(ElementName="result", Namespace="http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService/types/")]
    public Result Result { get; set; }
    [XmlAttribute(AttributeName="ns0", Namespace="http://www.w3.org/2000/xmlns/")]
    public string Ns0 { get; set; }
}

[XmlRoot(ElementName="Body", Namespace="http://schemas.xmlsoap.org/soap/envelope/")]
public class Body {
    [XmlElement(ElementName="getFlowTaskInstanceStatusResponse", Namespace="http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService/types/")]
    public GetFlowTaskInstanceStatusResponse GetFlowTaskInstanceStatusResponse { get; set; }
}

[XmlRoot(ElementName="Envelope", Namespace="http://schemas.xmlsoap.org/soap/envelope/")]
public class Envelope {
    [XmlElement(ElementName="Header", Namespace="http://schemas.xmlsoap.org/soap/envelope/")]
    public Header Header { get; set; }
    [XmlElement(ElementName="Body", Namespace="http://schemas.xmlsoap.org/soap/envelope/")]
    public Body Body { get; set; }
    [XmlAttribute(AttributeName="env", Namespace="http://www.w3.org/2000/xmlns/")]
    public string Env { get; set; }
    [XmlAttribute(AttributeName="wsa", Namespace="http://www.w3.org/2000/xmlns/")]
    public string Wsa { get; set; }
}

and DeSerialize it with:

string sampleXml;
sampleXml.DeSerializeXMLToObject<Header>();
Mahdi Anjam
  • 145
  • 1
  • 17
0

Thanks for the help. I found this solution online which solved my case to get the tag values with name spaces

XDocument xDoc = XDocument.Parse(response);
XNamespace rst = XNamespace.Get("http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService/types/");
var rslt = xDoc.Root.Descendants(rst + "result").First();
flowStatus = rslt.Value;