[Solved] How to consume a web service with headers C #? [closed]


Like this:

 public static string getResponseFromwebService(string serviceUrl)
    {

        var baseurl = "http://localhost:1936/";
        var auth= "123456";
        var apid = "1";

        var requestUrl = baseurl + serviceUrl;
        WebRequest request = WebRequest.Create(requestUrl);
        request.Headers.Add("Authorisation", auth);
        request.Headers.Add("appId", apid);
        WebResponse response = request.GetResponse();
        Stream dataStream = response.GetResponseStream();
        StreamReader reader = new StreamReader(dataStream);
        string responseFromServer = reader.ReadToEnd();
        reader.Close();
        response.Close();
        return responseFromServer;
    }

You’d want to keep the variables in some config, and probably serialize the response to objects of sorts.

2

solved How to consume a web service with headers C #? [closed]