【问题标题】:WCF wrapper for 3rd party web service - fire and forget [OperationContract(IsOneWay = true)]3rd 方 Web 服务的 WCF 包装器 - 触发并忘记 [OperationContract(IsOneWay = true)]
【发布时间】:2013-08-01 15:37:10
【问题描述】:

我创建了一个 WCF 服务,它是第三方 Web 服务的包装器,添加了一些附加功能。我遇到的问题是,在我的方法中,我想调用 3rd 方 Web 服务中的方法,但我不想等待这些方法的响应(Web 服务非常慢)。我曾尝试在我的方法上使用 [OperationContract(IsOneWay = true)] 但收到以下错误:

System.InvalidOperationException:在“MyService.MyService”类型的方法“MyMethod”上声明的 OperationContractAttribute 无效。 OperationContractAttributes 仅对在具有 ServiceContractAttribute 的类型中声明的方法有效。将 ServiceContractAttribute 添加到类型“MyService.MyService”或从方法“MyMethod”中删除 OperationContractAttribute。

在不调用第 3 方 Web 服务的方法上使用 [OperationContract(IsOneWay = true)] 可以正常工作。有没有办法做到这一点?

这是我正在采取的方法:

public string MyPublicMethod()
{
     //do some stuff

    SomeParams sp = new SomeParams{p1 = "A", P2 = "B"};
    //don't want to wait for this
    MyMethod(sp);

   // do some more stuff

}

[OperationContract(IsOneWay = true)]    
private void MyMethod(SomeParams someParams)
{
     //3rd party service
     WebInterop wisc = new WebInterop();
     var results = (XmlElement)wisc.Search(someParams);

     // do some processing on results


}

【问题讨论】:

  • 您能否提供一些示例代码,展示您如何使用 OneWay 等调用第三方服务和代码?
  • 我已经编辑了上面的问题。谢谢

标签: c# wcf web-services operation-contract


【解决方案1】:
猜你喜欢
  • 1970-01-01
  • 2012-12-04
  • 1970-01-01
  • 2012-03-10
  • 2012-12-17
  • 1970-01-01
  • 2011-01-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多