Click here to Skip to main content
15,663,225 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I consume web wervices using HTTP request object with XML Soap envolpe file.

1 solution

Your question is not clear, but here is some code which could help you starting...

If this is your rest service:

public class SendData
    public string cmd;

    public string data;

namespace My_Server
    public interface IRestService
        [WebInvoke(Method = "POST", 
		UriTemplate = "logon", 
		RequestFormat = WebMessageFormat.Xml, 
		ResponseFormat = WebMessageFormat.Xml, 
		BodyStyle = WebMessageBodyStyle.Bare)]
        LogonResult DoLogon(SendData data);

...then your client cmd could look like this:

private void DoLogon(string credentials)
    SendData sd = new SendData();
    sd.cmd = "EXTERNAL-USER"; = credentials;
    XmlDocument xdoc = HttpPost("https://yourserver-ip:443/internal/logon", sd);
    // convert xml document from the server to object of type LogonResult
    DataContractSerializer dcSer = new DataContractSerializer(typeof(LogonResult));
    StringWriter stringWriter = new StringWriter();
    XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter);
    MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(stringWriter.ToString()));
    stream.Position = 0;
    XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(stream, new XmlDictionaryReaderQuotas());
    LogonResult res = (LogonResult)dcSer.ReadObject(reader, true);
do something with the result...    

The class library to share between server and client:

namespace DataLib
    public class LogonResult
        public bool bCmdSuccess;
        public string sInfo;
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900