简体   繁体   English

第三方Web服务的WCF包装器-抛弃[OperationContract(IsOneWay = true)]

[英]WCF wrapper for 3rd party web service - fire and forget [OperationContract(IsOneWay = true)]

I have created a WCF service which is a wrapper for a third party web service adding some additional functionality. 我创建了WCF服务,该服务是第三方Web服务的包装,并添加了一些其他功能。 The issue I have is that within my methods I want to call methods in the 3rd party web service but I don't want to wait for a response (the web service is very slow) on these methods. 我的问题是,在我的方法中,我想调用第三方Web服务中的方法,但是我不想等待对这些方法的响应(Web服务非常慢)。 I have tried using [OperationContract(IsOneWay = true)] on my method but get the following error: 我尝试在我的方法上使用[OperationContract(IsOneWay = true)],但出现以下错误:

System.InvalidOperationException: The OperationContractAttribute declared on method 'MyMethod' in type 'MyService.MyService'is invalid. System.InvalidOperationException:在方法'MyMethod'上以类型'MyService.MyService'声明的OperationContractAttribute无效。 OperationContractAttributes are only valid on methods that are declared in a type that has ServiceContractAttribute. OperationContractAttributes仅对以具有ServiceContractAttribute的类型声明的方法有效。 Either add ServiceContractAttribute to type 'MyService.MyService' or remove OperationContractAttribute from method 'MyMethod'. 添加ServiceContractAttribute以键入“ MyService.MyService”,或从方法“ MyMethod”中删除OperationContractAttribute。

Using [OperationContract(IsOneWay = true)] on methods which don't call the 3rd party web service works fine. 在不调用第三方Web服务的方法上使用[OperationContract(IsOneWay = true)]可以正常工作。 Is there a way to do this? 有没有办法做到这一点?

This is the approach I am taking: 这是我采用的方法:

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


}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM