Web import javax jws Web Service public class
復習:Webサービスの構築開始 import javax. jws. *; @Web. Service public class Hello { public String say. Hello( String name ) { return “Hello, ” + name; } }
Webサービス実現まで hello/Hello. java をコンパイル hello/Hello. class を Glass. Fish の自動配備のディレクトリにコピー (glassfish/domains/domain 1/autodeploy)
自動生成(wsgenツール) javac hello/Hello. java wsgen -cp. hello. Hello hello. jaxws 以下に say. Hello. java, say. Hello. Response. java say. Hello. class say. Hello. Response. class (Hello. Service. wsdl, Hello. Service. Types. xsd)
補足: WSDLの取り扱いについて WSDL(Web Service Definetion Language) <definitions> <types> 利用するデータの型 </types> <message>交換されるデータ</message> <port. Type> <operation>メソッド定義</operation> </port. Type> <binding>通信プロトコル</binding> <service>サービス名、URL</service> </definitions>
クライアントプログラムの作成(1) 自動生成ツール wsimport Hello. Service. wsdl または wsimport http: //localhost/Service? wsdl Hello. class, Hello. Service. class, Object. Factory. class Say. Hello. class, Say. Hello. Response. class
クライアントプログラムの作成(2) public class Hello. Client { public static void main ( String[] args ) { Hello. Service service = new Hello. Service(); Hello port = service. get. Hello. Port(); String message =port. say. Hello( "Tatsuo" ); System. out. printf ( message ); }
もう少し複雑な例 package name; import javax. jws. *; @Web. Service public class Who. Are. You { public Name who() { Name name = new Name(); name. set. First( "George" ); name. set. Last( "Momma" ); return name; } public String iam( Name name ) { return "I see, " + name. get. First();
引数と返り値に定義されたクラス package name; public class Name { protected String first; public String get. First(){ return first; } public void set. First( String s ){ first=s; } protected String last; public String get. Last(){ return last; } public void set. Last( String s ){ last=s; } }
自動生成されるクラスの内容 wsgenで jaxws 化に4個のクラス Who. java, Who. Response. java Iam. java, Iam. Response. java プロパティにName型のデータ public class Iam { : public name. Name get. Arg 0() { }
クライアント側 name. Name クラスの情報はどこから? WSDL(にインクルードされるスキーマ内)に <xs: complex. Type name="name"> <xs: sequence> <xs: element name="first“ type="xs: string"/> <xs: element name="last" type="xs: string" /> </xs: sequence> </xs: complex. Type>
- Slides: 21