简体   繁体   English

nettcpbinding如何正确添加服务引用?

[英]nettcpbinding how add service reference correctly?

please help me. 请帮我。 I create service whith netTcpBinding and security mode="Message" message clientCredentialType="UserName" , this is my config 我创建服务netTcpBinding和安全mode="Message"消息clientCredentialType="UserName" ,这是我的配置

  <system.serviceModel>
<client>
  <endpoint address="http://topaznet.hq.eximb.com/RS/Svc/RS.svc"
    binding="wsHttpBinding" bindingConfiguration="wsHttpBindingEndpoint"
    contract="RSClient.IRS" name="wsHttpBindingEndpoint" />
</client>
<services>
  <service behaviorConfiguration="CredoServiceBehavior" name="CredoService.Credo">
    <endpoint address="" binding="netTcpBinding" name="netTcpBindingEndpoint"
      contract="CredoService.ICredo" />
    <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" endpointConfiguration="" />
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost/CredoService/" />
      </baseAddresses>
    </host>
  </service>
</services>

<bindings>
  <netTcpBinding>
    <binding name="netTcpBinding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
      <security mode="Message">
        <message clientCredentialType="UserName"/>
      </security>
    </binding>
  </netTcpBinding>
  </bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="CredoServiceBehavior">
      <serviceCredentials>
        <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="CredoService.Common.CustomUserNameValidator, CredoService"/>
        <serviceCertificate storeLocation="LocalMachine" storeName="My" x509FindType="FindByThumbprint" findValue="91797E67B20D0853A90CA8E228AF460A382ED94B" />
        <windowsAuthentication allowAnonymousLogons="true"/>
      </serviceCredentials>
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
      <serviceThrottling maxConcurrentCalls="2147483647" maxConcurrentSessions="2147483647" maxConcurrentInstances="2147483647"/>
      <dataContractSerializer maxItemsInObjectGraph="2147483647" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

Service hosted in IIS and work fine. 服务托管在IIS中,并且工作正常。 I create new windows forms project and click Add Service Reference, visual studio genetate for my config : 我创建新的Windows窗体项目,然后单击“添加服务参考”,Visual Studio为我的配置生成:

    <system.serviceModel>
    <bindings>
        <netTcpBinding>
            <binding name="netTcpBindingEndpoint1" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
                hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
                maxReceivedMessageSize="65536">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00"
                    enabled="false" />
                <security mode="Transport">
                    <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                    <message clientCredentialType="Windows" />
                </security>
            </binding>
        </netTcpBinding>
    </bindings>
    <client>
        <endpoint address="net.tcp://localhost/CredoService/Credo.svc"
            binding="netTcpBinding" bindingConfiguration="netTcpBindingEndpoint"
            contract="CredoClient.ICredo" name="netTcpBindingEndpoint">
            <identity>
                <servicePrincipalName value="host/home" />
            </identity>
        </endpoint>
    </client>
</system.serviceModel>

In this web config: 在此网络配置中:

                    <security mode="Transport">
                    <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                    <message clientCredentialType="Windows" />
                </security>

but in my service 但为我服务

  <security mode="Message">
    <message clientCredentialType="UserName"/>
  </security>

if i change this client dont work and throw exception. 如果我更改此客户端不起作用并引发异常。 How can i fix this? 我怎样才能解决这个问题?

I just spotted another issue with your code. 我刚刚发现了您的代码的另一个问题。 Your service isn't picking the binding! 您的服务没有选择绑定!

<endpoint address="" binding="netTcpBinding" name="netTcpBindingEndpoint"
  contract="CredoService.ICredo" />

needs to be 需要是

<endpoint address="" binding="netTcpBinding" bindingConfiguration="netTcpBinding" name="netTcpBindingEndpoint" contract="CredoService.ICredo" />

in your <services><service><endpoint> section. <services><service><endpoint>部分中。

That would explain why VS is going with default NetTcpBinding instead of your options. 这可以解释为什么VS使用默认的NetTcpBinding而不是您的选项。

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

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