Webサービスで(WSImportによって)生成される代わりにカスタムクラスを使用する必要があります
-
23-10-2019 - |
質問
次の問題を手伝ってください。
WSクライアントコード(WSImport ANTタスクを使用)を生成すると、すべてのクラスがWebサービスと同じパッケージ(HelloService.Endpointなど)で自動的に生成されます。たとえば、私のWebサービスにメソッドがある場合
public node getNode();
したがって、class helloservice.endpoint.nodeが生成されます。それにもかかわらず、私はWebサービスで使用したい独自のHelloService.Nodeクラスを持っています。
bind.xmlファイルを定義しました:
<bindings version="2.0" xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" >
<bindings node="wsdl:definitions/wsdl:portType[@name='Node']">
<class name="helloservice.Node"/>
</bindings>
</bindings>
バインディングパラメーターとしてWSImportタスクに渡しますが、エラーを取得します。
[wsimport] [ERROR] XPath evaluation of "wsdl:definitions/wsdl:portType[@name='Node']" results in empty target node
[wsimport] line 2 of file:/C:/work/projects/svn.ct/trunk/jwstutorial20/examples/jaxws/simpleclient/bind.xml
誰でも、ここで何が悪いのかをお勧めしますか?生成されたWebサービスクラスで自分のクラスをそのような方法で使用できますか、それともSMTHがより複雑になる必要がありますか?
前もって感謝します。
解決
WSDLからクラスを生成するには、ANTで使用します。
<taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport">
<wsimport keep="true" sourcedestdir="..." wsdl="..." wsdllocation="..." xnocompile="true" />
WSimport Antタスクで「パッケージ」属性を使用しないでください。そのため、すべてのクラスは正しいパッケージで作成されます。
一般に、パッケージをカスタマイズするには、XYZをXYZに追加するパッケージ名ABCを変更して、wsimportタスクに要素を追加し、次のようにbinging.jxbファイルを定義します。
<jxb:bindings version="1.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jxb:bindings schemaLocation="schema-for-a.b.c.xsd" node="/xs:schema">
<jxb:schemaBindings>
<jxb:package name="x.y.z" />
</jxb:schemaBindings>
</jxb:bindings>
</jxb:bindings>
Schema-for-ABCXSDは、WSGENタスクによって生成されるスキーマです(適切なスキームでWSDLを作成します)。
JAXBのカスタマイズについてより詳細: http://docs.oracle.com/cd/e17802_01/webservices/webservices/docs/1.6/tutorial/doc/javawstutorial.pdf, 、セクション「Jaxbバインディングのカスタマイズ」