WAS托管的nettcpbinding是不是不支持回调啊?
调用服务总是显示“Contract requires Duplex, but Binding 'NetTcpBinding' doesn't support it or isn't configured properly to support it.”
[解决办法]
不好意思,我没有看清楚,上面说的不对。
WCF回调要注意以下几点:
1、NetTcpBinding、NetNamedPipeBinding、WSDualHttpBinding都支持回调的
2、用 CallbackContract 为服务定义回调,回调的接口在服务端定义。
例:
[ServiceContract(CallbackContract = typeof(ISomeCallbackContract))]
3、服务端用 OperationContext.Current.GetCallbackChannel<T>()获取调用当前操作的客户端实例通道
例:ISomeCallbackContract callback = OperationContext.Current.GetCallbackChannel<ISomeCallbackContract>()
4、服务端获得客户端实例通道的对象以后就可以调用客户端方法
例:callback.SomeCallbackMethod2();
5、客户端生成代理以后,由客户端去实现回调接口
例:
public class CallBack : ServiceReferenceCallBack.IService1Callback
{
//实现接口
}
6、客户端创建回调的对象并生成操作调用的上下文并由客户端代理对象传回服务端
例:
ServiceReferenceCallBack.IService1Callback callback = new CallBack();
InstanceContext context = new InstanceContext(callback);
ServiceReferenceCallBack.Service1Client sc = new WCFPrograme.ServiceReferenceCallBack.Service1Client(context);
sc.DoSomething();
7、配置文件:使用wsDualHttpBinding的时候,需要在客户端配置文件中需要指定客户端基址clientBaseAddress,服务可以通过这个地址与客户端取得联系,这是因为wsDualHttpBinding需要两条http通道,而是使用netTcpBinding时不需要
例:
<endpoint address="http://localhost:8731/Design_Time_Addresses/WcfCallBack/Service1/"
binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IService1"
contract="ServiceReferenceCallBack.IService1" name="WSDualHttpBinding_IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_IService1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
clientBaseAddress="http://localhost:8008">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" />
<security mode="Message">
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsDualHttpBinding>
[解决办法]
net.tcp 是支持双工的,
IsOneWay 也是支持回调的,只是回调时不管状态,不阻塞。
楼主是用什么来 Host WCF啊,会不会是配置文件没有写对?
还有客户端用的是什么?