[英]WCF Duplex Contract
Say I have WCF service contract like this 说我有这样的WCF服务合同
[ServiceContract(CallbackContract = typeof(ICallback1),
SessionMode = SessionMode.Required)]
public interface IService1
{
// some methods
}
The service implementation has InstanceContextMode.Single
set for InstanceContextMode
and ICallback1
is something like 服务实现为
InstanceContextMode.Single
设置了InstanceContextMode
而ICallback1
就像
public interface ICallback1
{
[OperationContract]
void Report(int someValue);
}
Now on client side, I can have a class the implements ICallback1 like 现在在客户端,我可以有类实现ICallback1
class Callback1 : ICallback1
{
public void Report(int someValue)
{
// alert client
}
}
and I create client service reference like this 我像这样创建客户服务引用
Service1Client serviceClient = new Service1Client(new InstanceContext(new CallBack1()));
which works fine. 哪个工作正常。 Now the problem is that I have some clients that are not interested in the callback so I figured I do not require to implement the callback interface for such clients so I tried this
现在的问题是我有一些客户端对回调不感兴趣所以我认为我不需要为这样的客户端实现回调接口所以我试过这个
Service1Client serviceClient = new Service1Client(null);
and 和
Service1Client serviceClient = new Service1Client(new InstanceContext(null));
both reported that the parameter cannot be null
. 两者都报告
parameter cannot be null
。 My question is, how can i create a service reference without passing a callback object if the client is not interested in the callback. 我的问题是,如果客户端对回调不感兴趣,如何在不传递回调对象的情况下创建服务引用。 The only requirement is that all clients should be talking to the same service but otherwise I can restructure the service however.
唯一的要求是所有客户端都应该使用相同的服务,但我可以重新构建服务。 Any thoughts ?
有什么想法吗 ?
EDIT: 编辑:
I have also tried SessionMode = SessionMode.Allowed
for ServiceContract instead of SessionMode.Required
but that didn't help either. 我也尝试过
SessionMode = SessionMode.Allowed
for ServiceContract而不是SessionMode.Required
但这也没有帮助。
Workaround: Remove the CallbackContract from IService1. 解决方法:从IService1中删除CallbackContract。 Create IDuplexService1 which inherits IService1 and contains the CallbackContract.
创建继承IService1并包含CallbackContract的IDuplexService1。 Have Service1Client implement IDuplexService1.
让Service1Client实现IDuplexService1。 When instantiating the host, call
ServiceHost.AddServiceEndpoint
for both IService1 and IDuplexService1. 实例化主机时,请为IService1和IDuplexService1调用
ServiceHost.AddServiceEndpoint
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.