0

在我的 WCF 服务App.config中,我有:

<services>
  <service behaviorConfiguration="MyServiceWcfBehavior" name="MyService">
    <clear />
    <endpoint address="net.tcp://localhost:9999/MyService" binding="customBinding" bindingConfiguration="MyServiceTcpBinding" name="MyServiceWcfTcpEndpoint" contract="MyService.Contracts.Interfaces.IMy" />
  </service>
</services>

在我的测试客户端中,App.config我有:

<client>
  <endpoint address="net.tcp://localhost:9999/MyService" behaviorConfiguration="MyServiceEndpointBehavior" binding="customBinding" bindingConfiguration="MyServiceCustomTcpBinding" contract="MyService.Contracts.Interfaces.IMy" name="MyServiceWcfTcpEndpoint" />
</client>

然后我ServiceHost像这样实例化我的:

var host = new ServiceHost(typeof(MyService),new Uri(net.tcp://localhost:9999/MyService));
host.Open();

但是在运行我的服务然后使用我的客户端进行测试(调用我的服务中定义的通道端点)时,我得到运行时异常:

System.ServiceModel.FaultException`1 未处理 Action= http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher/fault HResult=-2146233087 Message=方法或操作未实现。Source=mscorlib StackTrace:服务器堆栈跟踪:在 System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime 操作,ProxyRpc& rpc) 在 System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) 在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime操作)在 System.ServiceModel.Channels。

4

1 回答 1

0

使用端口共享时,需要将一个NetTcpBindingwith PortSharingEnabledset to传递true给构造函数:

portsharingBinding = new NetTcpBinding();
portsharingBinding.PortSharingEnabled = true;

var host = new ServiceHost(typeof(MyService), portsharingBinding, new Uri("net.tcp://localhost:9999/MyService"));
host.Open();

此外,您是否确保您的服务实现了与 a 的接口ServiceContract

[ServiceContract]
interface IMyService 
{
    //Define the contract operations.  
}

class MyService : IMyService 
{  
    //Implement the IMyService operations. 
}

还要确保配置中的合同 MyService.Contracts.Interfaces.IMy与该接口完全匹配。这是区分大小写的。

于 2017-07-12T21:50:18.490 回答