0

netTcpBinding (トランスポート セキュリティ モードあり) で WCF サービスを作成します。

net.tcp://localhost/NetTcp/Service1.svc

自分のマシンでサービスをホストしてアクセスすると、機能します。しかし、リモートマシンでこのサービスをホストすると

net.tcp://192.168.0.1/NetTcp/Service1.svc

アクセスしようとすると、次のエラーが発生します。

サーバーはクライアント資格情報を拒否しました。

私の web.conf ファイルコードは次のとおりです。

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="netTcpConfig">
          <security mode="Transport">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign"></transport>
          </security>

        </binding>
      </netTcpBinding>
    </bindings>
    <services>
      <service name="NetTcpService.Service1" behaviorConfiguration="NetTcpBehavior">
        <endpoint address ="" 
                  contract="NetTcpService.IService1" 
                  binding="netTcpBinding" 
                  bindingConfiguration="netTcpConfig"/>
        <endpoint address="max" 
                  binding="mexTcpBinding" 
                  contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="NetTcpBehavior">
          <serviceMetadata httpGetEnabled="false"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

そして私のクラスは:

  string _uri = "net.tcp://192.168.0.1/NetTcp/Service1.svc";
                //ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(IgnoreCertificateErrorHandler);
                NetTcpBinding binding = new NetTcpBinding();
                binding.Security.Mode = SecurityMode.Transport;
                binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
                binding.Security.Transport.ProtectionLevel = ProtectionLevel.EncryptAndSign;
                EndpointAddress address = new EndpointAddress(_uri);
                ChannelFactory<IService1> channel = new ChannelFactory<IService1>(binding, address);
               // channel.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
                IService1 clientProxy = channel.CreateChannel();
                label1.Text = clientProxy.GetData(10011);

上記のコードで何が間違っていますか?

4

0 に答える 0