【发布时间】:2013-07-30 18:01:56
【问题描述】:
您好,我正在编写一个 WCF 服务不是托管在 IIS 上。它作为控制台应用程序在我的服务器上运行。 我有一个由上述服务调用的静态方法。
在这种方法中,我有发送短信的异步网络请求。
有时会发生从未收到短信的情况。经过一些调试后,我发现当我删除异步调用时,Web 请求有时会引发异常并显示消息:“操作已超时”。当我尝试在短时间内发送许多短信时会发生这种情况。
但是当我在浏览器中输入网络请求的地址时,一切正常。 (我按刷新的次数,无论多快,我收到短信的次数)我所拥有的如何才能做到这一点。
到目前为止我有
public static bool DoTheRequest(string number, string message)
{
try
{
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(string.Format("http://SomeURL?With={0}&something={1}", number, message));
myReq.BeginGetResponse(FinishWebRequest, myReq);
}
catch (Exception ex)
{
throw ex;
}
return true;
}
static void FinishWebRequest(IAsyncResult result)
{
HttpWebResponse response = (result.AsyncState as HttpWebRequest).EndGetResponse(result) as HttpWebResponse;
}
编辑:
以及服务定义:
[OperationContract]
void TestSms(string number);
和实施:
public void TestSms(string number)
{
Utilities.DoTheRequest(number, "THIS IS A TEST");
}
请帮忙
【问题讨论】:
标签: c# wcf asynchronous sms httprequest