2

场景是:我有两台台式机:

  1. WCF 服务托管在 ABC 桌面计算机上。
  2. 在 CDE 桌面上创建的控制台应用程序。

当我尝试使用控制台应用程序连接到我的 WCF 服务时,出现Logon Attempt Failed错误。

WCF 服务 ( web.config)

<system.serviceModel>
    <services>
      <service behaviorConfiguration="IISHost.Service1Behavior" name="IISHost.Service1">
        <endpoint address="" binding="wsHttpBinding" contract="IISHost.IService1">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
      <service behaviorConfiguration="IISHost.IISHostBehavior" name="IISHost.IISHost">
        <endpoint address="" binding="wsHttpBinding" contract="IISHost.IIISHost">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="IISHost.Service1Behavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
        <behavior name="IISHost.IISHostBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

控制台应用程序 ( app.config)

<configuration>
     <system.serviceModel>
         <bindings>
             <wsHttpBinding>
                 <binding name="WSHttpBinding_IIISHost" closeTimeout="00:01:00" 
                     openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                     bypassProxyOnLocal="false" transactionFlow="false"  
                     hostNameComparisonMode="StrongWildcard"
                     maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                     messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                     allowCookies="false">
                   <readerQuotas maxDepth="32" maxStringContentLength="8192" 
                                 maxArrayLength="16384" maxBytesPerRead="4096" 
                                 maxNameTableCharCount="16384" />
                     <reliableSession ordered="true" inactivityTimeout="00:10:00"
                         enabled="false" />
                    <security mode="Message"> 
                      <transport clientCredentialType="Windows" />
                      <message clientCredentialType="Windows" 
                               negotiateServiceCredential="true" algorithmSuite="Default"
                               establishSecurityContext="true" />
                     </security>
                 </binding>
             </wsHttpBinding>
         </bindings>
         <client>
             <endpoint address="http://yogeshpc/IISHost/IISHost.svc" 
                       binding="wsHttpBinding" 
                       bindingConfiguration="WSHttpBinding_IIISHost"  
                       contract="ServiceReference1.IIISHost"
                 name="WSHttpBinding_IIISHost">
                 <identity>
                     <dns value="localhost" />
                 </identity>
             </endpoint>
         </client>
     </system.serviceModel>
 </configuration>

控制台应用程序(.cs文件)

   static void Main(string[] args)
        {
            var d = new IISHostClient();
            d.ClientCredentials.Windows.ClientCredential.UserName = "YOGESH";
            //d.ClientCredentials.Windows.ClientCredential.Domain = "Workgroup";
            d.ClientCredentials.Windows.ClientCredential.Password = "abc@123";
            d.ClientCredentials.Windows.AllowNtlm = false;
            Console.WriteLine(d.add(30, 30));
            Console.ReadLine(); 
        }

注意:Console Application CS 文件中使用的用户名和密码是 ABC 桌面机器本地用户名和密码。

4

1 回答 1

2

我认为您在 Web 服务上的绑定缺少一些配置:

  <bindings>
<wsHttpBinding>
  <binding name = "someNameForTheBinding">
    <security mode="Message">
      <message clientCredentialType="Windows"/>
    </security>
  </binding>
</wsHttpBinding></bindings>

你可以在这里查看更多信息。

于 2013-05-31T09:45:31.330 回答