在 wse 中使用自己的異常,而不僅僅是 SoapException (Using own exceptions in wse, not only SoapException)


問題描述

在 wse 中使用自己的異常,而不僅僅是 SoapException (Using own exceptions in wse, not only SoapException)

是否可以通過 Soap 將我自己開發的異常發送到使用 http.sys 的客戶端??


參考解法

方法 1:

To the best of my knowledge unfortunately the answer is no. You cannot build your own custom exceptions on the server side and expect to use them on the client side through WSE. I can't give much technical background as to why (as in why this is not allowed by WSE), but I am sure about my answer because I tested this out.

You can use the approach described in the provided link to return a custom exception that inherits from a System.Web.Services.Protocols.SoapException, however you must capture the exception on the client side as a SoapException since you will not be able to capture it as the custom exception type: http://msdn.microsoft.com/en‑us/library/ms229064.aspx

To recreate the test for your own confirmation do the following:

  1. Create a test exception class, call it whatever you'd like and make sure it follows the pattern described in the link I provided above (there are code samples provided).
  2. Create a web method that explicitly returns the test exception like so:

    'This is in VB.Net
    <WebMethod()> _
    Public Function ThrowTestSoapException() As TestSoapException
        Return New TestSoapException()
    End Function
    
  3. Try to regenerate your client's WSE Library (using WseWsdl3.exe) and you should receive an error message like this one: "Error: Server unavailable, please try later"

That is as far as I could get when trying to create my own transferable Custom Exceptions. Again the only thing I was able to do was return a Custom Exception that inherited from the SoapException class, and caught it on the client side as a SoapException. That is the same method described in the link that "CheGueVerra" pointed out above.

In response to John Saunders's comment above: Yes, if possible move over to WCF, WSE is indeed obsolete. Since this is work related for me and for others asking these questions, making a shift from WSE to WCF would require managerial approval ‑ so some of us cannot make those changes easily ‑ even if we desperately want to.

方法 2:

Yes, you can throw your own exceptions. Any uncaught exception that does not derive from SoapException will be bottled up by the .NET framework into a SoapException. You can derive from SoapException if you want to control how certain parts of the SoapException are formed (for instance, the fault and detail portions).

方法 3:

Like the ASMX services it is based on, WSE has little support for SOAP Faults. You can return them (SoapException with Detail property set), but they won't appear in the WSDL. If received by a WSE client, they will appear as SoapException, not as a custom exception type.

WCF does have full support for SOAP faults, both on the client and the server side.

(by KaiSandyslexicanabokoZachJohn Saunders)

參考文件

  1. Using own exceptions in wse, not only SoapException (CC BY‑SA 2.5/3.0/4.0)

#wse #.net #C#






相關問題

Windows 2000 下的 WSE 服務器 (WSE Server under Windows 2000)

在 wse 中使用自己的異常,而不僅僅是 SoapException (Using own exceptions in wse, not only SoapException)

從Java調用.NET Web服務(WSE 2/3,WS-Security) (Calling .NET Web Service (WSE 2/3, WS-Security) from Java)

從 WCF 調用 WSE 服務的提示? (Tips for calling WSE service from WCF?)

在 Web 服務 (WSE) 中公開自定義類型(類) (exposing custom types (classes) in a web service (WSE))

在具有自定義類型的 WSE 服務中,構造函數是否在消費客戶端工作? (In WSE services, with custom types, do constructors work on the consuming client's side?)

從 Visual Studio 2005 遷移到 2008 時要注意什麼? (What to look out for when moving from Visual Studio 2005 to 2008?)

通過代理調用 WSE Web 服務 (Calling a WSE web-service though a proxy)

VS 2008 上的 WSE 2.0 SP2 (WSE 2.0 SP2 on VS 2008)

如何在使用 WCF(或 WSE 3)的 Web 服務客戶端應用程序的請求和響應中混合消息編碼類型(文本/MTOM)? (How do I mix message encoding types (Text/MTOM) in the Request & Response of a Web Service client application using WCF (or WSE 3)?)

從 wsdl 創建肥皂 Web 服務客戶端,沒有合同方法 (Create soap web service client from wsdl with no contract methods)

Windows 上的 X.509 證書入門 (Primer for X.509 certificates on Windows)







留言討論