我寫了下面的服務:捕獲由一個WebService拋出的SoapException
namespace WebService1
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string Test(string str)
{
if (string.IsNullOrEmpty(str))
throw new SoapException("message", SoapException.ClientFaultCode);
else
return str;
}
}
}
而且基本的應用程序進行測試(一個鍵調用單擊事件Test
法):
private void button1_Click(object sender, EventArgs e)
{
ServiceReference1.Service1SoapClient ws = new WindowsFormsApplication1.ServiceReference1.Service1SoapClient();
try
{
ws.Test("");
}
catch (SoapException ex)
{
//I never go here
}
catch (FaultException ex)
{
//always go there
}
catch (Exception ex)
{
}
}
我'd喜歡趕上由我的WebService拋出的SoapException
,但我總是去FaultException
catch塊a得到那個消息:
服務器無法處理消息 在WebService1.Service1.Test(字符串str)在[...] WebService1 \ WebService1 \ Service1.asmx.cs:行25
怎麼可能我趕上一個真正的SoapException
,而不是一個FaultException
?在WebService中有沒有我想念的東西?
-1:這是沒有必要使用舊技術在客戶端上,只是因爲舊技術在服務器上使用。 – 2011-02-17 14:42:46