Click here to Skip to main content
15,867,975 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have created on web service which receives request from one mobile application and forward it to one another server,and it reply back to the mobile application with the response which my web service has received.
Now my question is, how i can handle multiple requests from multiple mobile application to my web service, so my web service can serve each mobile application.


C#
public class Service1 : System.Web.Services.WebService
    {
        
        [WebMethod]
         public string postXMLData(String Session, String Token)
         {
             string destinationUrl = "https://data.getdata.com";
             String requestXml= "getmydata;";

             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(destinationUrl);
             byte[] bytes;
             bytes = System.Text.Encoding.ASCII.GetBytes(requestXml);
             request.ContentType = "text/xml; encoding='utf-8'";
             request.ContentLength = bytes.Length;
             request.Method = "POST";
             request.Headers.Add("ID","TPGETCOMPANIES");
             request.Headers.Add("SOURCE","EA");
             request.Headers.Add("TARGET","TNS");
             //request.Headers.Add("CONTENT-TYPE","text/xml;charset=utf-8");
             request.Headers.Add("Accept-Encoding","identity");
             Stream requestStream = request.GetRequestStream();
             requestStream.Write(bytes, 0, bytes.Length);
             requestStream.Close();
             HttpWebResponse response;
             response = (HttpWebResponse)request.GetResponse();
             if (response.StatusCode == HttpStatusCode.OK)
             {
                 Stream responseStream = response.GetResponseStream();
                 string responseStr = new StreamReader(responseStream).ReadToEnd().Trim();
                 return responseStr;
                 //responseStr.ToString();
             }
             else
             {
 
                 return "Problem in getting resp";
             
             }
             return null;
         }
 
    } 


What I have tried:

Do i need to use Async task in my Web service to handle this ?
Posted
Updated 14-Sep-16 2:00am
Comments
F-ES Sitecore 14-Sep-16 7:06am    
This is the job of the hosting service. If your webservice is hosted in IIS then IIS handles all this for you, you don't need to do anything.
Richard Deeming 14-Sep-16 9:34am    
REPOST
This is the same question you posted yesterday:
http://www.codeproject.com/Questions/1128775/How-to-use-async-task-concept-in-web-service-to-se[^]

Which I answered for you. Yesterday.

Why should anyone bother spending the time producing a detailed answer for you if you're just going to ignore it and re-post your question?!

1 solution

As mentioned in comments the server should handle that for you. If you find that your server cannot handle the load then you implement load balancing or some other technique but your code will stay the same, essentially.
 
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