设置 NetTcpBinding
Setting Up NetTcpBinding
正在设置 NetTcpBinding。尝试从服务器获取数据时出现错误。
已使用 WCFTestClient 进行测试。
我是 WCF 新手。我可能错过了 IIS 设置或绑定错误。请帮助我们理解问题。
The message with To
'net.tcp://wssekbdev-5-loc.wss.loc/_layouts/WSS/WSSC.V4.DMS.TestWCF.WcfService1/Service3.svc' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher. Check that the sender and receiver's EndpointAddresses agree.
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(IMessagereqMsg, IMessage retMsg) at
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at
IServiceContract.Login(String username) at
ServiceContractClient.Login(String username)
代码服务器
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
public class ServiceTest : IServiceContract
{
public string Login(string username)
{
return $"ok:{username}";
}
public void Message(string message, string userFrom)
{
}
}
[ServiceContract()]
public interface IServiceContract
{
[OperationContract]
string Login(string username);
[OperationContract(IsOneWay = true)]
void Message(string message, string userFrom);
}
配置
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="true" />
</system.webServer>
<system.web>
<httpRuntime />
<customErrors mode="RemoteOnly" />
<compilation targetFramework="4.5" />
<identity impersonate="false" />
</system.web>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="TestBinding" sendTimeout="00:01:00">
<reliableSession ordered="true" enabled="false" />
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="WSSC.V4.DMS.TestWCF.WcfService1.ServiceTest">
<endpoint binding="netTcpBinding" contract="WSSC.V4.DMS.TestWCF.WcfService1.IServiceContract"
bindingConfiguration="TestBinding"
/>
<endpoint binding="wsHttpBinding" contract="WSSC.V4.DMS.TestWCF.WcfService1.IServiceContract"/>
<endpoint address = "mex" binding = "mexTcpBinding" contract = "IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
如果您的服务在 Visual Studio 开发服务器中是 运行,则无法配置 netTcpBinding。原因是Visual Studio开发服务器只支持HTTP。
您需要像下面这样更改项目属性:
你也可以告诉我你调用服务时出现了什么错误,我帮你解决。
我根据您提供的信息创建了部署在IIS中的WCF项目,没有发现任何错误。
确保以下服务是 运行:
如果问题仍然存在,请随时告诉我。
项目设置指定正确。
我重新启动了 IIS,重新启动了服务,它起作用了。
非常感谢您的帮助。
正在设置 NetTcpBinding。尝试从服务器获取数据时出现错误。 已使用 WCFTestClient 进行测试。
我是 WCF 新手。我可能错过了 IIS 设置或绑定错误。请帮助我们理解问题。
The message with To
'net.tcp://wssekbdev-5-loc.wss.loc/_layouts/WSS/WSSC.V4.DMS.TestWCF.WcfService1/Service3.svc' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher. Check that the sender and receiver's EndpointAddresses agree.
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(IMessagereqMsg, IMessage retMsg) at
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at
IServiceContract.Login(String username) at
ServiceContractClient.Login(String username)
代码服务器
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
public class ServiceTest : IServiceContract
{
public string Login(string username)
{
return $"ok:{username}";
}
public void Message(string message, string userFrom)
{
}
}
[ServiceContract()]
public interface IServiceContract
{
[OperationContract]
string Login(string username);
[OperationContract(IsOneWay = true)]
void Message(string message, string userFrom);
}
配置
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="true" />
</system.webServer>
<system.web>
<httpRuntime />
<customErrors mode="RemoteOnly" />
<compilation targetFramework="4.5" />
<identity impersonate="false" />
</system.web>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="TestBinding" sendTimeout="00:01:00">
<reliableSession ordered="true" enabled="false" />
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="WSSC.V4.DMS.TestWCF.WcfService1.ServiceTest">
<endpoint binding="netTcpBinding" contract="WSSC.V4.DMS.TestWCF.WcfService1.IServiceContract"
bindingConfiguration="TestBinding"
/>
<endpoint binding="wsHttpBinding" contract="WSSC.V4.DMS.TestWCF.WcfService1.IServiceContract"/>
<endpoint address = "mex" binding = "mexTcpBinding" contract = "IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
如果您的服务在 Visual Studio 开发服务器中是 运行,则无法配置 netTcpBinding。原因是Visual Studio开发服务器只支持HTTP。
您需要像下面这样更改项目属性:
你也可以告诉我你调用服务时出现了什么错误,我帮你解决。
我根据您提供的信息创建了部署在IIS中的WCF项目,没有发现任何错误。
确保以下服务是 运行:
如果问题仍然存在,请随时告诉我。
项目设置指定正确。 我重新启动了 IIS,重新启动了服务,它起作用了。 非常感谢您的帮助。