线程在Web服务中 [英] Threading in web service

查看:87
本文介绍了线程在Web服务中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个Web服务,它接收来自一个移动应用程序的请求并将其转发给另一个服务器,并使用我的Web服务收到的响应回复移动应用程序。

现在我的问题是,我如何处理从多个移动应用程序到我的Web服务的多个请求,因此我的Web服务可以为每个移动应用程序提供服务。





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.


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;
         }
 
    } 





我尝试过:



我是否需要在我的Web服务中使用Async任务来处理这个问题?



What I have tried:

Do i need to use Async task in my Web service to handle this ?

推荐答案

如上所述评论服务器应该为您处理。如果您发现您的服务器无法处理负载,那么您实现负载平衡或其他一些技术,但实际上您的代码将保持不变。
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.


这篇关于线程在Web服务中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆