Consume SOAP and sending response back as Rest in C# RRS feed

  • Question

  • I am working with .net 4.5 C# project. I am consuming SOAP service and then response back them to with REST with SharePoint 2013.

    But the issue is part of SOAP response is not parsing as XML but as string. I don't know what I am doing wrong.

    Screen marked part parsing as string not XML

    Code for Consuming SOAP

    public HttpWebRequest CreateWebRequest(string URL)
    HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(@"" + URL);
    webRequest.ContentType = "text/xml;charset=\"utf-8\"";
    webRequest.Accept = "text/xml";
    webRequest.Method = "POST";
    return webRequest;
    public string ConsumeSOAP(string XML, string URL)
    HttpWebRequest request = CreateWebRequest(URL);
    XmlDocument soapEnvelopeXml = new XmlDocument();
    soapEnvelopeXml.LoadXml(@"" + XML);
    using (Stream stream = request.GetRequestStream())
    using (WebResponse response = request.GetResponse())
    using (StreamReader rd = new StreamReader(response.GetResponseStream()))
    string soapResult = rd.ReadToEnd();
    return soapResult;

    Code for SOAP response to REST

    public string doLogin(string memberId, string password)
    string XML = null;
    SOAPService soap = new SOAPService();
    XNamespace ns = @"http://schemas.xmlsoap.org/soap/envelope/";
    string URL = URL;
    string User = User;
    string Password = Password;
    string authenticateXML = string.Format(@"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:web=""http://webservices.xxx.xxx.com/"">
    </soapenv:Envelope>", Password, User, password, memberId);
    string authenticateResponse = soap.ConsumeSOAP(authenticateXML, URL);
    var authenticateResponseValue = XDocument.Parse(authenticateResponse);
    XML = authenticateResponseValue.Descendants((XNamespace)"http://schemas.xmlsoap.org/soap/envelope/" + "Body").First().FirstNode.ToString();
    return XML;

    Interface for the REST

    [WebGet(ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "/doLogin?memberId={memberId}&password={password}")]
    string doLogin(string memberId, string password);

    [1]: https://i.stack.imgur.com/na54O.png

    Friday, April 28, 2017 5:56 AM

All replies

  • Hi,

    The following code for your reference:

    using System.Xml;
    namespace REST_XML_LIST_GET
    	class Program
    		static XmlNamespaceManager xmlnspm = new XmlNamespaceManager(new NameTable());
    		static Uri sharepointUrl = new Uri("Site URL/");
    		static void Main(string[] args)
    			xmlnspm.AddNamespace("atom", "http://www.w3.org/2005/Atom");
    			xmlnspm.AddNamespace("d", "http://schemas.microsoft.com/ado/2007/08/dataservices");
    			xmlnspm.AddNamespace("m", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
    			NetworkCredential cred = new System.Net.NetworkCredential("username", password", "domain");
    			HttpWebRequest listRequest = (HttpWebRequest)HttpWebRequest.Create(sharepointUrl.ToString() + "_api/Web/lists/getByTitle('List Name')/items");
    			listRequest.Method = "GET";
    			listRequest.Accept = "application/atom+xml";
    			listRequest.ContentType = "application/atom+xml;type=entry";
    			listRequest.Credentials = cred;
    			HttpWebResponse listResponse = (HttpWebResponse)listRequest.GetResponse();
    			StreamReader listReader = new StreamReader(listResponse.GetResponseStream());
    			var listXml = new XmlDocument();
    			//Method 1 Seperate node list
    			var titleList = listXml.SelectNodes("//atom:entry/atom:content/m:properties/d:Title", xmlnspm);
    			var idList = listXml.SelectNodes("//atom:entry/atom:content/m:properties/d:ID", xmlnspm);
    			int i = 0;
    			foreach (XmlNode title in titleList)
    				Console.WriteLine(title.InnerXml+" "+idList[i++].InnerXml);
    			//Method 2 single node list
    			var prop = listXml.SelectNodes("//atom:entry/atom:content/m:properties", xmlnspm);
    			foreach (XmlNode ndlist in prop)
    				Console.WriteLine(ndlist.SelectSingleNode("d:Title", xmlnspm).InnerXml + " " + ndlist.SelectSingleNode("d:ID", xmlnspm).InnerXml);

    More information:

    Working With SharePoint 2013 REST API in a C# Managed Code


    Sharepoint 2013 REST API: The C# Connection: Part 1 Using System.Net.Http.HttpClient


    Step By Step Calling SharePoint 2013 REST API From C#.


    If you want to access SharePoint content in client side using C#, we can also use .NET client object Model to achieve it.

    Complete basic operations using SharePoint 2013 client library code


    Best Regards,


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, May 1, 2017 3:14 AM