我在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做同樣的,我得到了一個錯誤: 外層的異常:
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>
感謝您的幫助!
編輯:發佈中,我捕捉異常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;
}
這種分配新建分配FY爲int只是爲了得到這個例外在這個地方。
你可以發佈你的GUI的代碼,以防萬一有一些細微的差異在哪裏? – Jacob 2011-01-10 21:07:06