简体   繁体   English

使用tcpTransport的自定义绑定WCF

[英]Custom Binding WCF with tcpTransport

I have a WCF Service hosted on a Windows Service that runs on the same network using its own credentials. 我有一个WCF服务托管在Windows服务上,该服务使用自己的凭据在同一网络上运行。 Security is not important. 安全性并不重要。 However, speed and reliability are important. 但是,速度和可靠性很重要。

So, I tried with a netTcpBinding binding. 因此,我尝试使用netTcpBinding绑定。 However, I noticed that when I reference the Service into the client. 但是,我注意到当我将服务引用到客户端时。 It adds to the configuration file the identity tag with the information of the account that the service is running on: 它将identity标签添加到配置文件中,该标签包含运行服务的帐户的信息:

<identity>
    <userPrincipalName value="account@domain" />
</identity>

I really don't want to have this in the client's configuration file, nor I want to pass it programmatically. 我真的不想在客户端的配置文件中使用它,也不想以编程方式传递它。

When I use instead a basicHttpBinding , I noticed that it does not add this tag. 当我改用basicHttpBinding ,我注意到它没有添加该标签。 However, I still want to stick with net.tcp. 但是,我仍然要坚持使用net.tcp。 So, my next try was to use a customBinding 因此,我的下一个尝试是使用customBinding

So, here is where my problem is. 所以,这就是我的问题所在。 I am not able to reference the custom binding to the client. 我无法引用到客户端的自定义绑定。 Can someone verify my configuration? 有人可以验证我的配置吗? Also. 也。 Will this be enough to ignore completely the identity tag? 这足以完全忽略身份标签吗? If this is not the proper way, what would be the proper way? 如果这不是正确的方法,那将是正确的方法? Thanks 谢谢

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

First, the reason that we could not reference the custom binding to the client is we should add MEX service endpoint and enable the service metadata behavior. 首先,我们无法引用到客户端的自定义绑定的原因是我们应该添加MEX服务端点并启用服务元数据行为。 Like below, 像下面一样

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

Besides, if we don't want to add the identity tag to the client configuration, just we need to do is to set the Security Mode to NONE. 此外,如果我们不想在客户端配置中添加身份标签,则只需将“安全模式”设置为“无”即可。 As shown above. 如上图所示。
For Mex endpoint details. 有关Mex端点的详细信息。
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/metadata https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/metadata
Feel free to let me know if there is anything I can help with. 请随时告诉我是否有什么我可以帮助的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM