问题描述
契约:namespaceContract{[ServiceContract(Namespace="http://www.artech.com/",SessionMode=SessionMode.Required,CallbackContract=typeof(ICallBack))]publicinterfaceIMyContract{[OperationContract(IsOneWay=true,IsInitiating=true,IsTerminating=false)]voidSend(HD_UNI_FRMfrm);}publicinterfaceICallBack{[OperationContract(IsOneWay=true,IsInitiating=true,IsTerminating=false)]voidServerReturn(HD_UNI_FRMfrm);}}实现契约:publicclassContractService:IMyContract{publicvoidSend(SocketLibrary.HD_UNI_FRMfrm){try{MyData.callback=OperationContext.Current.GetCallbackChannel<ICallBack>();MyData.callback.ServerReturn(frm);}catch(Exceptione){}}}服务端配置文件:<?xmlversion="1.0"?><configuration><system.serviceModel><services><servicename="TestHost.ContractService"><endpointaddress="net.tcp://192.168.1.103:7001/ContractService"binding="netTcpBinding"contract="Contract.IMyContract"/></service></services></system.serviceModel></configuration>web客户端调用:publicstaticvoidRequest(SocketLibrary.HD_UNI_FRMfrm){InstanceContextinstanceContext=newInstanceContext(newWCFCallBack());DuplexChannelFactory<IMyContract>channelFactory=newDuplexChannelFactory<IMyContract>(instanceContext,"ContractService");IMyContractproxy=channelFactory.CreateChannel();proxy.Send(frm);}回调实例:publicclassWCFCallBack:ICallBack{publicvoidServerReturn(SocketLibrary.HD_UNI_FRMfrm){WCFDelegateInvoke.InvokeCallBack(frm);}}回调委托:publicdelegatevoidCallBackDelegate(SocketLibrary.HD_UNI_FRMfrm);publicclassWCFDelegateInvoke{publicstaticeventCallBackDelegateCallBackEvent;publicstaticvoidInvokeCallBack(SocketLibrary.HD_UNI_FRMfrm){if(CallBackEvent!=null){CallBackEvent(frm);}}}web客户端配置文件:<?xmlversion="1.0"?><configuration><system.web><compilationdebug="true"targetFramework="4.0"/></system.web><system.serviceModel><client><endpointname="ContractService"address="net.tcp://192.168.1.103:7001/ContractService"binding="netTcpBinding"contract="Contract.IMyContract"/></client></system.serviceModel></configuration>在winform中回调正常,但是在web中回调网页直接关闭,求高人指点.
解决方案
解决方案二:
没人知道么?顶下
解决方案三:
iis默认不支持tcp端口监听呀。