你们能指出我在这里缺少的东西吗?
我有两个示例项目。两个控制台应用程序(.Net 3.5)。这是“服务器”方面:
class Program
{
static void Main()
{
var baseAddresses = new Uri("net.tcp://localhost:9000/WcfServiceLibrary/svc");
var host = new ServiceHost(typeof(UiWcfSession), baseAddresses);
var reliableSession = new ReliableSessionBindingElement { Ordered = true, InactivityTimeout = TimeSpan.MaxValue };
var binding = new CustomBinding(reliableSession, new TcpTransportBindingElement()) { ReceiveTimeout = TimeSpan.MaxValue };
host.AddServiceEndpoint(typeof(IClientFulfillmentPipeService), binding, k.WinSvcEndpointName);
host.Open();
Thread.CurrentThread.Join();
}
}
不确定它是否重要,但这里只是IClientFulfillmentPipeService
[ServiceContract(CallbackContract = typeof (IClientFulfillmentPipeServiceCallbacks), SessionMode = SessionMode.Required)]
public interface IClientFulfillmentPipeService
{
[OperationContract(IsOneWay = true)]
void Initialize(int uiProcessId, string key);
}
[ServiceContract]
public interface IClientFulfillmentPipeServiceCallbacks
{
[OperationContract(IsOneWay = true)]
void ShowBalloonTip(int timeout, string tipTitle, string tipText, BalloonTipIcon tipIcon);
}
最后是客户
private void OpenConnection()
{
try
{
var ep = new EndpointAddress("net.tcp://localhost:9000/WcfServiceLibrary/svc");
var reliableSession = new ReliableSessionBindingElement {Ordered = true};
Binding binding = new CustomBinding(reliableSession, new TcpTransportBindingElement());
reliableSession.InactivityTimeout = TimeSpan.MaxValue;
var pipeFactory = new DuplexChannelFactory<IClientFulfillmentPipeService>(this, binding, ep);
commChannel = pipeFactory.CreateChannel();
((IChannel) commChannel).Open(OpenConnectionTimeout);
}
catch (Exception ex)
{
Log.ErrorFormat("The communication channel to the windows service could not be established. {0}", ex.Message);
}
}
客户端失败并出现System.ServiceModel.EndpointNotFoundException
异常,其中说明:“没有端点侦听net.tcp:// localhost:9000 / WcfServiceLibrary / svc可以接受该消息。这通常是由不正确的地址或SOAP操作。有关更多详细信息,请参阅InnerException(如果存在)。“
这是使用命名管道的生产代码的修改,我想将其转换为Tcp传输。
谢谢!
答案 0 :(得分:1)
我不小心将k.WinSvcEndpointName
留在了服务器的端点定义中。这就是问题所在。