ViShal
ViShal

Reputation: 13

Get an error of "The server has rejected the client credentials" in WCF Service call

I create WCF service with netTcpBinding(With transport security mode).

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

when I host service in my machine and access it get worked. But when i host this service on remote machine

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

and try to access than it gives an following error:

The server has rejected the client credentials.

My web.conf file code is:

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

And my Class is:

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

What is wrong in above code?

Upvotes: 0

Views: 467

Answers (0)

Related Questions