[英]WCF Service : config address
In my WCF Service App.config
I have : 在我的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>
And in my test-client App.config
I have : 在我的测试客户端
App.config
我有:
<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 : 然后我像这样实例化我的
ServiceHost
:
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.
未处理System.ServiceModel.FaultException`1 Action = http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher/fault HResult = -2146233087 Message =方法或操作未实现。 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)
Source = mscorlib StackTrace:服务器堆栈跟踪:位于System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime操作,ProxyRpc&处,位于System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(消息答复,MessageFault错误,字符串操作,MessageVersion版本,FaultConverter faultConverter)。 rpc)位于System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime)(字符串操作,布尔型单向,ProxyOperationRuntime操作,Object [] ins,Object [] outs,TimeSpan超时) System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage消息)上的异常重新抛出:[0]:System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg)在System.Runtime.Remoting.Proxies .RealProxy.PrivateInvoke(MessageData&msgData,Int32类型)
When using Port sharing, you need to pass a NetTcpBinding
with PortSharingEnabled
set to true
to the constructor: 使用端口共享时,需要将
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();
Also, your have you made sure that your service implements an interface with the a ServiceContract
另外,您是否已确保服务实现了与
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. 还要确保配置
MyService.Contracts.Interfaces.IMy
中的协定与该接口完全匹配。 This is case sensitive. 这是区分大小写的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.