0
votes

In my WCF Service App.config I have :

<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>

And in my test-client App.config I have :

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

Then I instantiate my ServiceHost like this :

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

But on running my service and then testing with my client ( calling channel endpoint defined in my service ) I get runtime exception :

System.ServiceModel.FaultException`1 was unhandled Action=http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher/fault HResult=-2146233087 Message=The method or operation is not implemented. Source=mscorlib StackTrace: Server stack trace: at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter) at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)

1
Is the method you're trying to call via the test client implemented in the service?Tim

1 Answers

0
votes

When using Port sharing, you need to pass a NetTcpBinding with PortSharingEnabled set to true to the constructor:

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

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

Also, your have you made sure that your service implements an interface with the a ServiceContract

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

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

Also make sure the contract in your config MyService.Contracts.Interfaces.IMy matches that interface exactly. This is case sensitive.