开发者

Catch Unauthorized exception

开发者 https://www.devze.com 2022-12-28 20:43 出处:网络
I am connectin开发者_Go百科g to a webservice in my project by entereing user credentials(user name and password) i need to catch a unauthorized exception when the user enter invalid username/password.

I am connectin开发者_Go百科g to a webservice in my project by entereing user credentials(user name and password) i need to catch a unauthorized exception when the user enter invalid username/password. How can i do that


Are you attempting to catch an exception before calling the webservice?

try
{
    result = Service.GetResult(param1, param2);
}
catch(System.Net.WebException ex)
{
    Logger.WriteError("Error calling Webservice: ", ex.ToString());
}

WebException will catch server return codes as errors I believe, such as HTTP status 404: Not Found etc.


Is your web service SOAP? Are you using WCF on on the service side? If so, take a look at a Specifying and Handling Faults

0

精彩评论

暂无评论...
验证码 换一张
取 消