在我的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 消息=未实现的方法或操作。 来源=mscorlib 堆栈跟踪: 服务器堆栈跟踪: at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstand(Message 回复, 消息错误错误, 字符串操作, 消息版本版本, 故障转换器故障转换器( at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime 操作,ProxyRpc& rpc( at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, 对象[] outs,TimeSpan 超时( at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage 方法调用,代理操作运行时操作( at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage 消息( 在 [0] 处重新引发异常: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg( at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData,Int32 类型(
使用端口共享时,需要将PortSharingEnabled
设置为true
的NetTcpBinding
传递给构造函数:
portsharingBinding = new NetTcpBinding();
portsharingBinding.PortSharingEnabled = true;
var host = new ServiceHost(typeof(MyService), portsharingBinding, new Uri("net.tcp://localhost:9999/MyService"));
host.Open();
此外,您是否确保您的服务实现了具有ServiceContract
[ServiceContract]
interface IMyService
{
//Define the contract operations.
}
class MyService : IMyService
{
//Implement the IMyService operations.
}
还要确保配置MyService.Contracts.Interfaces.IMy
中的协定与该接口完全匹配。这区分大小写。