如何在C#Web服务中实现线程 [英] how to implement Threading in C# web service

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

问题描述



我已经创建了Web服务.服务器频繁将数据推送到我的服务(15分钟内发送1000次).我想发送确认说xml是正确的,并且需要在发送确认后处理该数据.

如何在Web服务中实现这一目标?

Hi,

I have created web service. Server is pushing data to my service frequently (1000 in in 15 min). I want to send acknoledgement saying xml is correct and need to process that data after sendin acklowledge.

How can i achieve this in web service?

[WebMethod]
public string temp(string)
{
     //validate xml
     // store into obj

i want to implement threading here 
     //send acknowledgement


     //do some calculations on data and store into database
 }


请帮助我如何实现这一目标?

谢谢.


Please help me how to achieve this?

Thank you.

推荐答案

个人而言,我认为将线程放入Web服务不是一个好主意,尤其是当它在运行IIS时托管在IIS中时将IIS工作进程置于不正常状态的风险.我会像往常一样创建另一个自托管的WCF服务,该服务隐藏在您的Web服务器后面.该服务进行处理.

创建此服务时,请使用操作合同选项上的IsOneWay选项.用一种方式签约,呼叫不等待过程完成,而只是发送数据.

以下是有关单向合同的信息.

http://msdn.microsoft.com/en-us/library/ms733035.aspx [ ^ ]

请注意,所有示例均返回void.那是因为他们不等,他们无法返回任何内容,因此必须返回void.
Personally I don''t think putting threading into a web service is a very good idea especially if it''s IIS hosted as you run the risk of putting the IIS worker processes into an unhealthy state. I''d create another WCF service, self hosted, as is always my preference, which is hidden somewhere behind your web servers. This service does the processing.

When you create this service, make use of the IsOneWay option on the operation contract option. With one way contracts the call doesn''t wait for the process to the complete, it simply sends the data.

The following is information about one way contracts.

http://msdn.microsoft.com/en-us/library/ms733035.aspx[^]

Note all the examples return void. That''s because they don''t wait, they can''t return anything so they have to return void.


我希望我可以使用WCF.但要求仅使用VS 2005和Web服务(ASMX/SOAP).因此,如果可以的话,请提出其他建议以在Web服务中实现此目标.

谢谢.
I wish i could use WCF. But requirement is to use VS 2005 and web service(ASMX / SOAP) only. So if you can please give any other suggetion to acheive this in web service.

Thank you.


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

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