【问题标题】:Custom Binding WCF with tcpTransport使用 tcpTransport 自定义绑定 WCF
【发布时间】:2019-11-21 06:25:08
【问题描述】:

我有一个托管在 Windows 服务上的 WCF 服务,该服务使用自己的凭据在同一网络上运行。安全并不重要。但是,速度和可靠性很重要。

所以,我尝试使用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>

【问题讨论】:

    标签: c# .net wcf configuration app-config


    【解决方案1】:

    首先,我们无法将自定义绑定引用到客户端的原因是我们应该添加 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>
    

    此外,如果我们不想在客户端配置中添加身份标签,只需将安全模式设置为无。如上图。
    有关 Mex 端点的详细信息。
    https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/metadata
    如果有什么我可以帮忙的,请随时告诉我。

    【讨论】:

    • 谢谢。这无需创建自定义绑定即可工作。保安的行为确实有些奇怪。这是我发现的post 讨论这个问题。因为我没有&lt;dns/&gt; 标签,所以我遇到了这个问题。真是奇怪的东西!
    • 但是对于你的例子,我不需要做任何与Identity 相关的事情。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-05
    • 2010-11-29
    • 1970-01-01
    • 2012-05-25
    相关资源
    最近更新 更多