我有一个在IIS中托管的WCF Web服务.这是相同的配置:
当我尝试在我的WinForms客户端中使用此特定服务(当作为服务引用添加时)时,它会抛出此异常:
The username is not provided. Specify username in ClientCredentials.
但是当我将服务添加为“Web引用”时,我可以完美地执行所有方法.
name="EMSService.EMSCRUD">
bindingConfiguration="BasicHttpEndpointBinding"
name="BasicHttpEndpoint" contract="EMSService.IEMSCRUD">
添加为服务引用时的代码:
EE.EMSCRUDClient obj = new EE.EMSCRUDClient();
obj.ClientCredentials.Windows.ClientCredential.UserName = "demo";
obj.ClientCredentials.Windows.ClientCredential.Password = "demo";
obj.ClientCredentials.Windows.ClientCredential.Domain = "demo";
obj.somemethod(); //Error here
添加为Web引用时的代码:
testEMService.EMSCRUD ob = new testEMService.EMSCRUD();
ICredentials credentials = new NetworkCredential("user", "pass");
ob.Credentials = credentials;
ob.somemethod();//No error