使用 tcpTransport 自定义绑定 WCF
Custom Binding WCF with tcpTransport
我有一个 WCF 服务托管在 Windows 服务上,该服务使用自己的凭据在同一网络上运行。安全并不重要。然而,速度和可靠性很重要。
所以,我尝试使用 netTcpBinding
绑定。但是,我注意到当我将服务引用到客户端时。它向配置文件添加 identity
标签,其中包含服务 运行 上的帐户信息:
<identity>
<userPrincipalName value="account@domain" />
</identity>
我真的不想在客户端的配置文件中有这个,也不想以编程方式传递它。
当我改用 basicHttpBinding
时,我注意到它没有添加此标签。不过,我还是想坚持net.tcp。所以,我的下一次尝试是使用 customBinding
所以,这就是我的问题所在。我无法将自定义绑定引用到客户端。有人可以验证我的配置吗?还。这足以完全忽略身份标签吗?如果这不是正确的方法,那么正确的方法是什么?谢谢
<system.serviceModel>
<services>
<service name="LicenseServiceLogic.LicenseService">
<endpoint address="net.tcp://localhost:8000/LicenseService"
binding="myCustomBinding"
contract="LicenseServiceLogic.ILicenseService">
</endpoint>
</service>
</services>
<bindings>
<customBinding>
<binding name="myCustomBinding">
<compactMessageEncoding>
<binaryMessageEncoding/>
</compactMessageEncoding>
<tcpTransport listenBacklog ="100"
maxBufferPoolSize ="524288"
maxBufferSize ="2147483647"
maxReceivedMessageSize ="2147483647"/>
</binding>
</customBinding>
</bindings>
<client>
<endpoint binding="customBinding"
bindingConfiguration="myCustomBinding"
contract="IMetadataExchange"
name="http" />
</client>
</system.serviceModel>
首先,我们无法将自定义绑定引用到客户端的原因是我们应该添加 MEX 服务端点并启用服务元数据行为。如下图,
<system.serviceModel>
<services>
<service name="VM1.MyService" behaviorConfiguration="mybehavior">
<endpoint address="" binding="netTcpBinding" contract="VM1.IService" bindingConfiguration="mybinding">
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" ></endpoint>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:5566"/>
</baseAddresses>
</host>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="mybinding">
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="mybehavior">
<serviceMetadata />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
此外,如果我们不想在客户端配置中添加身份标签,只需将安全模式设置为NONE即可。如上图
有关 Mex 端点的详细信息。
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/metadata
如果有什么我可以帮忙的,请随时告诉我。
我有一个 WCF 服务托管在 Windows 服务上,该服务使用自己的凭据在同一网络上运行。安全并不重要。然而,速度和可靠性很重要。
所以,我尝试使用 netTcpBinding
绑定。但是,我注意到当我将服务引用到客户端时。它向配置文件添加 identity
标签,其中包含服务 运行 上的帐户信息:
<identity>
<userPrincipalName value="account@domain" />
</identity>
我真的不想在客户端的配置文件中有这个,也不想以编程方式传递它。
当我改用 basicHttpBinding
时,我注意到它没有添加此标签。不过,我还是想坚持net.tcp。所以,我的下一次尝试是使用 customBinding
所以,这就是我的问题所在。我无法将自定义绑定引用到客户端。有人可以验证我的配置吗?还。这足以完全忽略身份标签吗?如果这不是正确的方法,那么正确的方法是什么?谢谢
<system.serviceModel>
<services>
<service name="LicenseServiceLogic.LicenseService">
<endpoint address="net.tcp://localhost:8000/LicenseService"
binding="myCustomBinding"
contract="LicenseServiceLogic.ILicenseService">
</endpoint>
</service>
</services>
<bindings>
<customBinding>
<binding name="myCustomBinding">
<compactMessageEncoding>
<binaryMessageEncoding/>
</compactMessageEncoding>
<tcpTransport listenBacklog ="100"
maxBufferPoolSize ="524288"
maxBufferSize ="2147483647"
maxReceivedMessageSize ="2147483647"/>
</binding>
</customBinding>
</bindings>
<client>
<endpoint binding="customBinding"
bindingConfiguration="myCustomBinding"
contract="IMetadataExchange"
name="http" />
</client>
</system.serviceModel>
首先,我们无法将自定义绑定引用到客户端的原因是我们应该添加 MEX 服务端点并启用服务元数据行为。如下图,
<system.serviceModel>
<services>
<service name="VM1.MyService" behaviorConfiguration="mybehavior">
<endpoint address="" binding="netTcpBinding" contract="VM1.IService" bindingConfiguration="mybinding">
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" ></endpoint>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:5566"/>
</baseAddresses>
</host>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="mybinding">
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="mybehavior">
<serviceMetadata />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
此外,如果我们不想在客户端配置中添加身份标签,只需将安全模式设置为NONE即可。如上图
有关 Mex 端点的详细信息。
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/metadata
如果有什么我可以帮忙的,请随时告诉我。