开发者

Specified throwing AxisFault in WSDL file

I generate my web service from WSDL file. But 开发者_开发技巧I need t o define in this file that my methods in SkeletonInterface thow Axis Fault Exception. Smth like:

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

In which way I can do this (in WSDL).

Thanks.


In short, it's bad practice to reuse AxisFault for your own application faults. When I see AxisFault, it signals that something internal to the Axis autogen code failed. This could include your exception wrapped inside of it.

First, I want to address your pseudcode.

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

This pseudocode indicates that you want a method with no input, no output, but still have an exception. If I assume this, then that design is not recommended (I'm not even sure if it is possible). If you want something to trigger something to happen with no output, an empty output message is preferable to an exception. Exceptions should only be used when something uncommon happens.

If you meant the above code as an abstract example and you do have input/output, then the correct approach would be to make up your own fault. Using your own fault allows you to control behavior and more accurately describe what is failing. You may also need several faults in the future so using AxisFault is not beneficial in that case.

<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>

That said, AxisFault does happen for web service operation calls. For your client stub code, it should throw a RemoteException. If you take a look at your autogen Stub code, you should see that does in fact throw an AxisFault which extends RemoteException.


using the faults

<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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜