0

Basically my idea is to develop a proxy which will run in windows

I have created windows service application which running successfully and i have integrated a web service code in the windows service application running in windows service.

How to call that web service method when the client hits my url?

How to form the url which can call web service method to get the method return value?

sandeep
  • 77
  • 1
  • 11
  • 1
    _Did you tried anything so far?_ Show your work.. – Soner Gönül Apr 02 '13 at 07:42
  • 1
    This question is too broad, in order for people to help you, please try to ask a specific question e.g. in your question, it is not clear, weather you need architectural guidance or a specific code example. – Ali Khalid Apr 02 '13 at 07:45
  • @sandeep it depends on web service type. See my answer with instructions of calling REST and SOAP web services – illegal-immigrant Apr 02 '13 at 07:59

1 Answers1

2

OK, I'll try to answer.

  • Let's assume you want to call REST web service. What do you need? A HttpClient and (probably) JSON/XML Serializer. You can use built-in .NET classes, or a library like RestSharp

Sample calling REST web service using RestSharp

var client = new RestClient("http://example.com");
// client.Authenticator = new HttpBasicAuthenticator(username, password);

var request = new RestRequest("resource/{id}", Method.POST);
request.AddParameter("name", "value"); // adds to POST or URL querystring based on Method
request.AddUrlSegment("id", 123); // replaces matching token in request.Resource

// easily add HTTP Headers
request.AddHeader("header", "value");

// add files to upload (works with compatible verbs)
request.AddFile(path);

// execute the request
RestResponse response = client.Execute(request);
var content = response.Content; // raw content as string

// or automatically deserialize result
// return content type is sniffed but can be explicitly set via RestClient.AddHandler();
RestResponse<Person> response2 = client.Execute<Person>(request);
var name = response2.Data.Name;

// easy async support
client.ExecuteAsync(request, response => {
    Console.WriteLine(response.Content);
});

// async with deserialization
var asyncHandle = client.ExecuteAsync<Person>(request, response => {
    Console.WriteLine(response.Data.Name);
});

// abort the request on demand
asyncHandle.Abort();

You are not required to use RestSharp, no. For simple cases HttpWebRequest (+DataContractJsonSerializaer or Xml analogue) will be just perfect

  • Having SOAP web service? Follow the instructions provided here
Community
  • 1
  • 1
illegal-immigrant
  • 8,089
  • 9
  • 51
  • 84