2011-06-06 71 views
0

我從WSDL文件生成我的Web服務。但是我不需要在這個文件中定義我在SkeletonInterface中的方法,它就是Axis Fault Exception。 水木清華這樣的:指定在WSDL文件中拋出AxisFault

void method() throws AxisFault{....} 

在哪種方式,我可以做到這一點(在WSDL)。

謝謝。使用故障

<definitions ...> 

    <message name="empty"/> 
    <message name="InsufficientFundsFault"> 
    <part name="balance" type="xsd:int"/> 
    </message> 

    <portType name="Bank"> 
    <operation name="throwException"> 
     <input message="tns:empty"/> 
     <output message="tns:empty"/> 
     <fault name="fault" message="tns:InsufficientFundFault"/> 
    </operation> 
    </portType> 
    ... 
</definitions> 

回答

1

總之

+0

Thanks.Could你告訴我在哪裏可以指定異常的類型嗎?(例如type =「org.apache.axis2.AxisFault」) – Oleksandr 2011-06-07 05:34:26

+0

我不確定我是否理解你的問題。當您運行'wsdl2java'時,Axis2會自動生成您的異常代碼。 – BennyMcBenBen 2011-06-07 16:14:48

0

,這是不好的做法重用AxisFault爲自己的應用程序故障。當我看到AxisFault時,它表示Axis自動編碼內部的某些內容失敗。這可能包含你的異常包裝在它內部。

首先,我想解決你的僞代碼。

void method() throws AxisFault{....} 

這個僞代碼表明你想要一個沒有輸入,沒有輸出但仍然有異常的方法。如果我假設這一點,那麼不推薦這種設計(我甚至不確定是否有可能)。如果你想要某些東西在沒有輸出的情況下觸發某個事件,那麼空的輸出消息比異常更可取。只有在發生不常見的情況時才應使用例外。

如果你的意思是上面的代碼是一個抽象的例子,並且你有輸入/輸出,那麼正確的方法就是彌補你自己的錯誤。使用自己的錯誤可以讓您控制行爲並更準確地描述失敗的情況。您未來可能還需要幾個故障,因此在這種情況下使用AxisFault不是有益的。

<wsdl:definitions ...> 
... 
    <wsdl:message name="MyFault"> 
    <wsdl:part name="parameters" element="def:MyFault"> 
    </wsdl:part> 
    </wsdl:message> 

    <wsdl:portType name="MyPortType"> 
    <wsdl:operation name="doStuff"> 
     <wsdl:input message="tns:MyRequest"> 
    </wsdl:input> 
     <wsdl:output message="tns:MyResponse"> 
    </wsdl:output> 
     <wsdl:fault name="MyFault" message="tns:MyFault"> 
    </wsdl:fault> 
    </wsdl:operation> 
    </wsdl:portType> 

    <wsdl:binding name="MyBinding" type="tns:MyPortType"> 
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> 
    <wsdl:operation name="doStuff"> 
     <soap:operation soapAction="namespace/operationName"/> 
     <wsdl:input name="MyRequest"> 
     <soap:body use="literal"/> 
     </wsdl:input> 
     <wsdl:output name="MyResponse"> 
     <soap:body use="literal"/> 
     </wsdl:output> 
     <wsdl:fault name="MyFault"> 
    <soap:body use="literal"/> 
     </wsdl:fault> 
    </wsdl:operation> 
    </wsdl:binding> 

    ... 
</wsdl:definitions> 

也就是說,AxisFault確實發生的Web服務操作調用。對於您的客戶端存根代碼,它應該拋出RemoteException。如果你看看你的autogen存根代碼,你應該看到它確實會拋出一個AxisFault,它擴展了RemoteException

相關問題