Click here to Skip to main content
15,885,546 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.
Thanks
Posted

1 solution

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

If this is your rest service:

C#
[DataContract]
[Serializable]
public class SendData
{
    [DataMember(Order=1)]
    public string cmd;

    [DataMember(Order=2)]
    public string data;
}

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


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

C#
private void DoLogon(string credentials)
{
    SendData sd = new SendData();
    sd.cmd = "EXTERNAL-USER";
    sd.data = 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);
    xdoc.WriteTo(xmlWriter);
    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:

C#
namespace DataLib
{
    [Serializable]
    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