全部博文(322)
分类: 系统运维
2010-12-03 15:11:10
package test.jws.service;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
@WebService(targetNamespace = "")
@SOAPBinding(style = SOAPBinding.Style.RPC)
publicclass HelloWorld {
@WebMethod(action="toSayHello",operationName="toSayHello",exclude=false)
@WebResult(name="returnWord")//自定义该方法返回值在WSDL中相关的描述
public String sayHello(@WebParam(name="userName")String userName) {
return"Hello:" + userName;
}
@WebMethod
publicint getExp(int i, int j) {
return i / j;
}
} |
package test.jws.service;
import javax.xml.ws.Endpoint;
publicclass StartService {
publicstaticvoid main(String[] args) {
Endpoint.publish("", new HelloWorld());
}
}
|
xml
version="1.0" encoding="UTF-8" ?>
<definitions
xmlns=""
xmlns:tns=""
xmlns:xsd=""
xmlns:soap="soap/"
targetNamespace=""
name="HelloWorldService">
<types />
<message
name="toSayHello">
<message
name="getExp">
<message
name="getExpResponse">
<portType
name="HelloWorld">
<operation
name="toSayHello"
parameterOrder="userName">
<operation
name="getExp"
parameterOrder="arg0 arg1">
<binding
name="HelloWorldPortBinding" type="tns:HelloWorld">
transport="" />
<operation
name="toSayHello">
<input>
namespace="" />
<output>
namespace="" />
<operation
name="getExp">
<input>
namespace="" />
<output>
namespace="" />
binding>
<service
name="HelloWorldService">
binding="tns:HelloWorldPortBinding">
location="" />
definitions> |
package test.jws.client;
import test.jws.client.ref.*;
publicclass ClientRun {
/**
*@paramargs
*/
publicstaticvoid main(String[] args) {
HelloWorldService hws = new HelloWorldService();
HelloWorld hw
= hws.getHelloWorldPort();
System.out.println(hw.getExp(9, 3));
System.out.println(hw.toSayHello("zhuoshiyao"));
}
} |