WCF“目标名称不正确或服务器已拒绝客户端凭据。”

时间:2011-03-09 22:01:52

标签: c# wpf wcf

我收到“目标名称不正确或服务器拒绝了客户端凭据。”将配置从localhost更改为QA服务器时出现错误消息。

以下是代码失败的地方:

          ServiceReference1.MaestroServiceClient client; 

        try

        {
            client = new ServiceReference1.MaestroServiceClient("NamedPipes");

            client.ClientCredentials.UserName.UserName = "xxx";
            client.ClientCredentials.UserName.Password = "xxx";

            // fails on this line
            lbRateCards.ItemsSource = ((System.Data.DataTable)client.GetRateCardsDataTable(networkId)).DefaultView;
            lbRateCards.DisplayMemberPath = "RATECODE";
            lbRateCards.SelectedValuePath = "RATECARDID";
        }
        catch (Exception ex) 
        {
            lbRateCard.Content = ex.Message + ": " + ex.StackTrace.ToString();
        }

我添加了用户名和密码,看看是否会影响结果。正如您所看到的,它连接到服务但在执行方法时失败。

感谢任何帮助。我整个星期都在敲打我的头。

下面是我的app.config。我将从WPF浏览器应用程序转到wfc服务。

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IMaestroService" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
      maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
      useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
  <netNamedPipeBinding>
    <binding name="NamedPipes" 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>
  <netTcpBinding>
    <binding name="NetTcpBinding_IMaestroService" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
      hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288"
      maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00"
        enabled="false" />
      <security mode="Transport">
        <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
        <message clientCredentialType="Windows" />
      </security>
    </binding>
  </netTcpBinding>
</bindings>
<client>
  <endpoint address="http://xxx:8080/MaestroService/basic"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMaestroService"
    contract="ServiceReference1.IMaestroService" name="BasicHttpBinding_IMaestroService" />
  <endpoint address="net.tcp://xxx:8888/MaestroService" binding="netTcpBinding"
    bindingConfiguration="NetTcpBinding_IMaestroService" contract="ServiceReference1.IMaestroService"
    name="NetTcpBinding_IMaestroService">
    <identity>
      <userPrincipalName value="[username]@[domain]" />
      <dns/>
    </identity>
  </endpoint>
  <endpoint address="net.pipe://lax-qa-rests01/MaestroService" binding="netNamedPipeBinding"
    bindingConfiguration="NamedPipes" contract="ServiceReference1.IMaestroService"
    name="NamedPipes">
    <identity>

      <userPrincipalName value="[username]@[domain]" />
      <dns value ="xxx"/>

    </identity>
  </endpoint>
</client>

1 个答案:

答案 0 :(得分:1)

除非您的WPF应用程序也在QA服务器上运行,否则您无法将配置从localhost更改为QA服务器(在这种情况下,您仍然可以使用localhost)。 WCF中命名管道的限制是它只能用于同一台机器上的进程间通信。因此,如果您的客户端和服务在不同的计算机上运行,​​则无法使用基于命名管道的绑定进行通信。