c# – 如何使用WebInvokeAttribute异步调用WCF服务方法?

c# – 如何使用WebInvokeAttribute异步调用WCF服务方法?,第1张

概述我有这种方法的WCF服务.该方法具有WebInvoke属性.我怎么能异步调用它? [WebInvoke(UriTemplate = "*", Method = "*")]public Message HandleRequest(){ var webContext = WebOperationContext.Current; var webClient = new WebClie 我有这种方法的WCF服务.该方法具有WebInvoke属性.我怎么能异步调用它?

[WebInvoke(UriTemplate = "*",Method = "*")]public Message HandleRequest(){    var webContext = WebOperationContext.Current;    var webClIEnt = new WebClIEnt();    return webContext.CreateStreamResponse(webClIEnt.OpenRead("http://site.com"),"text/HTML");}
解决方法 您可以通过将以下值一起传递给ServiceBehavior属性来为服务类定义异步行为:

> InstanceContextMode = InstanceContextMode.Single,
> ConcurrencyMode = ConcurrencyMode.Multiple.

生成的代码可能如下所示:

[ServiceContract][ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,ConcurrencyMode = ConcurrencyMode.Multiple)]public class MyService{    [WebInvoke(UriTemplate = "*",Method = "*")]    public Message HandleRequest()    {        var webContext = WebOperationContext.Current;        var webClIEnt = new WebClIEnt();        return webContext.CreateStreamResponse(webClIEnt.OpenRead("http://site.com"),"text/HTML");    }}
总结

以上是内存溢出为你收集整理的c# – 如何使用WebInvokeAttribute异步调用WCF服务方法?全部内容,希望文章能够帮你解决c# – 如何使用WebInvokeAttribute异步调用WCF服务方法?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/langs/1229671.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存