2011-01-10 2 views
2

У меня есть большая проблема с пользовательской аутентификацией имени пользователя в WCF. Я сделал простую службу WCF, которая нуждается в проверке пользователей через CustomUserValidator. Когда я вхожу в из консольного приложения, как это:Проблема аутентификации WCF

using (var svc = new ServiceReference2.DBServiceClient()) 
{ 
    Console.WriteLine("Username: "); 
    string user = Console.ReadLine(); 
    Console.WriteLine("Pass: "); 
    string pass = Console.ReadLine(); 
    svc.ClientCredentials.UserName.UserName=user; 
    svc.ClientCredentials.UserName.Password=pass; 
    Console.WriteLine(svc.GetAllDepartmentList().First().DepartmentID); 
    Console.Read(); 
} 

Все это хорошо, но когда я хочу использовать GUI клиента, который essentialy сделать то же самое, я получил сообщение об ошибке: Outer Exception:

Secure channel cannot be opened because security negotiation with the remote endpoint has failed. This may be due to absent or incorrectly specified EndpointIdentity in the EndpointAddress used to create the channel. Please verify the EndpointIdentity specified or implied by the EndpointAddress correctly identifies the remote endpoint.

Внутренняя Исключение:

The request for security token has invalid or malformed elements.

запись app.config для них обоих одинакова:

<system.serviceModel> 
    <bindings> 
    <wsHttpBinding> 
     <binding name="WSHttpBinding_IDBService" 
     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" 
      proxyCredentialType="None" realm="" /> 
      <message clientCredentialType="UserName" 
      negotiateServiceCredential="true" algorithmSuite="Default" /> 
     </security> 
     </binding> 
    </wsHttpBinding> 
    </bindings> 
    <client> 
    <endpoint name="WSHttpBinding_IDBService" 
     address="http://localhost:8732/Design_Time_Addresses/DBService/Service1/" 
     binding="wsHttpBinding" 
     bindingConfiguration="WSHttpBinding_IDBService" 
     contract="ServiceReference2.IDBService" > 
     <identity> 
     <dns value="localhost" /> 
     </identity> 
    </endpoint> 
    </client> 
</system.serviceModel> 

Спасибо за вашу помощь!

Edit: размещение GUI код, в котором я поймать исключение:

  using (var svc = new DBServiceHost.DBServiceClient()) 
     { 
      svc.ClientCredentials.UserName.UserName = view.userName; 
      svc.ClientCredentials.UserName.Password = view.userPass; 
      int asd = svc.GetCompanies().First().CompanyID;     
     } 

Это распайка к ИНТ только, чтобы получить это исключение в этом месте.

+0

Можете ли вы опубликовать код своего GUI на всякий случай, если есть что-то тонкое, что делает разницу? – Jacob

+0

В вашем консольном приложении вы создаете клиент ServiceReference2.DBServiceClient, но в своем приложении пользовательского интерфейса вы создаете DBServiceHost.DBServiceClient. Изменяет ли ваш конфиг эти изменения имен? –

+0

Да, DBServiceHost - это ссылка на ту же службу, только в приложении UI. Я делаю это имя, а консольное приложение выполняется быстро со стандартными именами – Pax0r

ответ

0

Попробуйте запустить приложение Gui, щелкнув правой кнопкой мыши Run As Admin. Также убедитесь, что вы обрезаете поля view.userName. Задний пробел может создать проблему.

Смежные вопросы