【问题标题】:WCF Windows Authentication ErrorWCF Windows 身份验证错误
【发布时间】:2009-05-25 11:39:49
【问题描述】:

我正在尝试通过 WCF 控制台应用程序使用服务。但我得到的唯一响应是“远程服务器返回了意外响应:(400) 错误请求。”

服务配置有以下选项:

<services>
  <service name="TryOut.BasicService" behaviorConfiguration="NicksBasicBehavior">
    <host>
      <baseAddresses>
        <add baseAddress="http://192.168.10.67:8000/Service" />
      </baseAddresses>
    </host>

    <endpoint address ="http://192.168.10.67:8000/Service"

              name="NicksEndpoint"
              binding="basicHttpBinding"
              contract="TryOut.IBasicService"
              bindingConfiguration="BasicBinding"
              />
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="NicksBasicBehavior">       
      <serviceMetadata httpGetEnabled="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

<binding name="BasicBinding">
    <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows"/>
    </security>
</binding>

我的客户端的配置文件如下:

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="NicksEndpoint" 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="TransportCredentialOnly">
        <transport clientCredentialType="Windows" proxyCredentialType="None"
            realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://192.168.10.67:8000/Service" binding="basicHttpBinding"
      bindingConfiguration="NicksEndpoint" contract="ServiceReference1.IBasicService"
      name="NicksEndpoint" />
</client>

现在,当我在与服务相同的 PC 上启动客户端时,一切正常。但是,如果我尝试在不在服务器 PC 域中的机器上运行客户端,则会出现错误,尽管我在客户端代码中提供了登录信息:

c.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("Nick", "password", "mydomain");

有人知道我做错了什么,我该如何解决?谢谢你的期待!

【问题讨论】:

    标签: c# wcf authentication


    【解决方案1】:

    根据这个article on MSDN,您似乎需要以不同的方式指定您的凭据:

    WCFTestService.Service myService = new WCFTestService.Service();
    myService.Credentials = System.Net.CredentialCache.DefaultCredentials;
    MessageBox.Show(myService.GetData(123, true));
    myService.Dispose();
    

    您可以尝试使用此代码并尝试将 Windows 凭据传递到 myService.Credentials 吗?这行得通吗?

    马克

    【讨论】:

      【解决方案2】:

      您是否尝试过在客户端端点的身份元素中指定 userPrincipalName?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-02-16
        • 2011-07-22
        • 1970-01-01
        • 2013-07-10
        • 2015-06-13
        • 2012-03-24
        • 1970-01-01
        • 2011-10-09
        相关资源
        最近更新 更多