简体   繁体   中英

Returning a user friendly error message to client, from a web service

I need to return an error message to the client, if they have entered invalid data when calling my web service. So if my code is:

    If Not IsNumeric(strOrderID) Then
    Throw New SoapException("Invalid Order ID", SoapException.ClientFaultCode)
End If

I get a web page saying:
System.Web.Services.Protocols.SoapException: Invalid Order ID at Service.GetHeaderValues(String strOrderID)

Is there a way to display a more user friendly error message (such as a message box or just the words "Invalid Order ID")?

我的语法可能有点不对,但是您可以使用类似

return <err>ex.message</err>

You'll need to catch the exception at the client and handle it appropriately (display message, log it, whatever).

The WebService would/could never "show" anything to the user itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM