你如何赶上从Web服务的SOAP抛出异常? [英] How do you catch a thrown soap exception from a web service?

查看:227
本文介绍了你如何赶上从Web服务的SOAP抛出异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网络服务丢几个肥皂异常成功。我想捕获异常和访问字符串和ClientFaultCode被调用除外。下面是我在Web服务异常的一个例子:

I throw a few soap exceptions in my web service successfully. I would like to catch the exceptions and access the string and ClientFaultCode that are called with the exception. Here is an example of one of my exceptions in the web service:

throw new SoapException("You lose the game.", SoapException.ClientFaultCode);

在我的客户,我尝试运行从Web服务,可能会抛出异常的方法,和我抓住它。问题是,我的catch块没有做任何事情。见这个例子:

In my client, I try to run the method from the web service that may throw an exception, and I catch it. The problem is that my catch blocks don't do anything. See this example:

try
{
     service.StartGame();
}
catch
{
     // missing code goes here
}

我怎样才能访问字符串和ClientFaultCode被调用抛出的异常?

How can I access the string and ClientFaultCode that are called with the thrown exception?

推荐答案

抓住的SoapException 实例。您可以访问其信息的这种方式:

Catch the SoapException instance. That way you can access its information:

try {
     service.StartGame();
} catch (SoapException e)  {
    // The variable 'e' can access the exception's information.
}

这篇关于你如何赶上从Web服务的SOAP抛出异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆