在从Visual Studio UI添加引用后,我初始化了客户端:
现在,当URL、用户名和密码正确时,一切正常。但是,如果URL、用户名或密码错误,应用程序会崩溃,并且在调试时Visual Studio会显示此窗口,跳过我的catch块:
private WcfRequestProcessorClient _client;
var binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
string serviceFullUrl = "http://myserviceurl.com/svcapi";
var address = new EndpointAddress(serviceFullUrl);
_client = new WcfRequestProcessorClient(binding, address);
_client.ClientCredentials.UserName.UserName = "MyUserName";
_client.ClientCredentials.UserName.Password = "MyPassword";
后来,我使用该请求作为参数调用相关方法:
try
{
var itemsReq = LoadItemsRequest();
_client.ProcessRequestsAsync(itemsReq);
}
catch(Exception)
{
// source code for show an error in a popup
}
现在,当URL、用户名和密码正确时,一切正常。但是,如果URL、用户名或密码错误,应用程序会崩溃,并且在调试时Visual Studio会显示此窗口,跳过我的catch块:
有什么方法可以处理这些类型的异常吗?
catch(Exception e){Console.WriteLine(e.Message);}
- Amit Kumar Ghosh