3

我有一个带有 NetNamedPipe 的 WCF 服务,用于进程间通信,我想在它上面添加安全性。没有安全性,一切都很好,但是当我尝试使用传输安全性时,我收到“InvalidCredentialException:服务器已拒绝客户端凭据”异常。你能帮我么?

代码示例:

var netPipeBinding = new NetNamedPipeBinding() { MaxReceivedMessageSize = 2147483647, SendTimeout = TimeSpan.FromMinutes(10), ReceiveTimeout = TimeSpan.FromMinutes(10) };
netPipeBinding.ReaderQuotas.MaxDepth = 2147483647;
netPipeBinding.ReaderQuotas.MaxStringContentLength = 2147483647;
netPipeBinding.ReaderQuotas.MaxArrayLength = 2147483647;
netPipeBinding.ReaderQuotas.MaxBytesPerRead = 2147483647;
netPipeBinding.ReaderQuotas.MaxNameTableCharCount = 2147483647;
netPipeBinding.Security.Mode = NetNamedPipeSecurityMode.Transport;
netPipeBinding.Security.Transport.ProtectionLevel = ProtectionLevel.EncryptAndSign;
var host = new ServiceHost(typeof(MainService));
var netPipeEA = new EndpointAddress(new Uri("net.pipe://MyProject/ServerSide"));
var contractDescription = ContractDescription.GetContract(typeof (IMainService), typeof (MainService));
host.AddServiceEndpoint(new ServiceEndpoint(contractDescription, netPipeBinding, netPipeEA));
host.Opened += HostOnOpened;
host.Open();

...

...

    private void HostOnOpened(object sender, EventArgs eventArgs)
    {
        var netPipeBinding = new NetNamedPipeBinding() { MaxReceivedMessageSize = 2147483647, SendTimeout = TimeSpan.FromMinutes(10), ReceiveTimeout = TimeSpan.FromMinutes(10) };
        netPipeBinding.ReaderQuotas.MaxDepth = 2147483647;
        netPipeBinding.ReaderQuotas.MaxStringContentLength = 2147483647;
        netPipeBinding.ReaderQuotas.MaxArrayLength = 2147483647;
        netPipeBinding.ReaderQuotas.MaxBytesPerRead = 2147483647;
        netPipeBinding.ReaderQuotas.MaxNameTableCharCount = 2147483647;
        netPipeBinding.Security.Mode = NetNamedPipeSecurityMode.Transport;
        netPipeBinding.Security.Transport.ProtectionLevel = ProtectionLevel.EncryptAndSign;

        DuplexChannelFactory<IMainService> channelFactory = new DuplexChannelFactory<IMainService>(new InstanceContext(new CalbackHandler()), netPipeBinding,
                                                                                                                               new EndpointAddress(IMainService));

        var proxy = channelFactory.CreateChannel();
        proxy.DoPing();
    }

谢谢

4

1 回答 1

0

机器名称,在本例中为“localhost”,因为您使用的是命名管道,应在 EndpointAddress URI 中定义。

于 2014-02-18T05:07:53.517 回答