使用管道获取' System.ServiceModel.Security.SecurityNegotiationException'在Windows服务中部署WCF服务

时间:2010-11-15 01:45:31

标签: wcf wcf-binding

我们已经创建了一个托管为Windows服务的WCF服务。我们的服务与我们的应用程序一起安装在计算机上,永远不会从其他客户端远程访问。所以,我们设计它来使用命名管道......在我们的开发计算机上,它在我们安装和运行我们的服务和应用程序时非常有效。但是,当我们将应用程序和服务部署到测试计算机并运行它时,我们会收到SecurityNegotiationException,这是由于我们的应用程序在启动时对服务进行的调用。如果我注释掉这个服务调用,只要它不使用该服务,我们的应用程序就会加载并正常运行。我已经浏览了互联网,看看如何解决这个问题,但我找不到任何特别针对WCF + Windows Service +命名管道的东西。我真的很感激你的帮助!

谢谢,

麦克

异常

框架版本:v4.0.30319 描述:由于未处理的异常,进程终止。 异常信息:System.ServiceModel.Security.SecurityNegotiationException 堆栈:

服务器堆栈跟踪:    在System.ServiceModel.Channels.WindowsStreamSecurityUpgradeProvider.WindowsStreamSecurityUpgradeInitiator.OnInitiateUpgrade(Stream stream,SecurityMessageProperty& remoteSecurity)    at System.ServiceModel.Channels.StreamSecurityUpgradeInitiatorBase.InitiateUpgrade(Stream stream)    在System.ServiceModel.Channels.ConnectionUpgradeHelper.InitiateUpgrade(StreamUpgradeInitiator upgradeInitiator,IConnection& connection,ClientFramingDecoder decoder,IDefaultCommunicationTimeouts defaultTimeouts,TimeoutHelper& timeoutHelper)    在System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.SendPreamble(IConnection连接,ArraySegment`1前导码,TimeoutHelper& timeoutHelper)    在System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.DuplexConnectionPoolHelper.AcceptPooledConnection(IConnection连接,TimeoutHelper& timeoutHelper)    在System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan超时)    在System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan超时)    在System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)    在System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan超时)    在System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)    在System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan超时,CallOnceManager级联)    在System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan超时)    在System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime operation,Object [] ins,Object [] outs,TimeSpan timeout)    在System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime操作)    在System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage消息)    在ClientSaver.MainForm..ctor()    在ClientSaver.Program.Main()

=============================================== ==========

SERVICE'S APP.CONFIG FILE

<system.serviceModel>
    <services>
        <service behaviorConfiguration="" name="ClientSaver.VssService.VssService">
            <endpoint address="Pipe" binding="netNamedPipeBinding"
                bindingConfiguration="" contract="ClientSaver.VssService.IVssService" />
            <host>
                <baseAddresses>
                    <add baseAddress="net.pipe://localhost/VssService/" />
                </baseAddresses>
            </host>
        </service>
    </services>

  <behaviors>
    <serviceBehaviors>
    </serviceBehaviors>
  </behaviors>      
</system.serviceModel>

=============================================== ============

===客户来自其APP.CONFIG ==

的WCF信息
    <bindings>
          <netNamedPipeBinding>
                <binding name="NetNamedPipeBinding_IVssService" closeTimeout="00:01:00"
                      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                      transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
                      hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288"
                      maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
                      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                      <security mode="Transport">
                            <transport protectionLevel="EncryptAndSign" />
                      </security>
                </binding>
          </netNamedPipeBinding>
    </bindings>
    <client>
          <endpoint address="net.pipe://localhost/VssService/Pipe" binding="netNamedPipeBinding"
                bindingConfiguration="NetNamedPipeBinding_IVssService" contract="VssService.IVssService"
                name="NetNamedPipeBinding_IVssService">
                <identity>
                      <servicePrincipalName value="host/DEVPC_W7.aboh.local" />
                </identity>
          </endpoint>
    </client>
    <services>
        <service name="ClientSaver.VssService.VssService">
            <endpoint address="net.pipe://localhost" binding="netNamedPipeBinding"
                bindingConfiguration="" contract="ClientSaver.VssService.IVssService" />

            <endpoint address="http://localhost/VssService/" binding="basicHttpBinding"
                bindingConfiguration="" contract="ClientSaver.VssService.IVssService" />                            
        </service>
    </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="VssServiceBehavior">
        <serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />
      </behavior>
    </serviceBehaviors>
  </behaviors>      
</system.serviceModel>

2 个答案:

答案 0 :(得分:1)

使用NetNamedPipeBinding时,默认情况下会配置传输安全性。这会在打开通道时导致客户端和服务通道堆栈之间的安全协商。您在启动此协商期间发生例外。 (有关如何发生这种情况的详细信息,请参阅here。)

请您提供有关如何配置WCF客户端的详细信息。异常的Message属性的值也是有价值的诊断信息。我的猜测是客户端的安全配置与服务显示的默认配置之间存在一些不匹配。

答案 1 :(得分:0)

命名管道绑定仅用于进程内服务/客户端。这意味着服务和客户端必须位于同一台计算机上。

如果您同时使用WCF开发了客户端和服务,请尝试使用TcpBinding。