我具有以下OperationContract设置,该设置可以同步工作,但是当从客户端异步调用时却无能为力:
[OperationContract]
[WebGet(UriTemplate = "startExport", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
void Export();
方法“ Export()”的设置如下:
public void Export()
{
var aProc = Process.Start("LongRunning.exe"));
aProc.WaitForExit();
//Trigger a message on the server interface to say the exe has completed
}
服务器设置如下:
WebServiceHost _oHost = new WebServiceHost(typeof(DataService), new Uri("http://localhost:7000/"));
var oRestBinding = new WebHttpBinding
{
CloseTimeout = TimeSpan.MaxValue,
OpenTimeout = TimeSpan.MaxValue,
ReceiveTimeout = TimeSpan.MaxValue,
SendTimeout = TimeSpan.MaxValue
};
_oHost.AddServiceEndpoint(typeof(ExternalComms), oRestBinding, "http://localhost:7000/");
有人知道为什么只能通过WebRequest.GetResponse()而不是WebRequest.GetResponseAsync()触发Export方法吗?我需要的是对服务器的REST调用,不会阻止客户端。
我还在客户端尝试了以下操作,但结果与WebRequest.GetResponseAsync()相同(未触发服务器方法'Export()')
const string url = @"http://localhost:7000/startExport";
var request = (HttpWebRequest)WebRequest.Create(url);
ThreadPool.QueueUserWorkItem(o => { request.GetResponse(); });