我使用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);
上面的代码有什么问题?