面向服务的应用程序开发:SOAP异常与WCF服务全解析
1. SOAP异常处理
在服务调用过程中,可能会出现各种错误。当服务端无法处理请求(如服务崩溃或出现故障)时,我们需要设置相应的错误代码。若客户端传递了错误的消息或参数值,可将值设为 ClientFaultCode 。此外,还有两个重要的属性:
- Actor :用于将值设置为Web服务的URI,它代表引发异常的代码。
- Detail(可选) :用于传递关于给定错误的更多信息,此属性可以不包含任何内容,也可以包含你想提供的关于异常的详细信息。
以下是一个 GetCustomerProfile Web方法的新版本示例,该版本会检查客户是否存在,若不存在则抛出一个 SoapException ,并将 Code 属性设置为 ClientFaultCode :
[WebMethod(Description = "Used to return a customer’s profile.")]
public Customer GetCustomerProfile(string customerId) {
EntityServices.CustomerProfile custProfile = new EntityServices.CustomerProfile();
Customer customer = custP
超级会员免费看
订阅专栏 解锁全文
17

被折叠的 条评论
为什么被折叠?



