时间:2021-07-01 10:21:17 帮助过:254人阅读
import javax.jws.WebMethod;
import javax.jws.WebService;
/**
* Created with IntelliJ IDEA.
* User: Administrator
* Date: 14-3-5
* Time: 下午3:11
*/
@WebService(targetNamespace = "http://xxx.com/wsdl")
public interface CalculatorWs {
@WebMethod
public int sum(int add1, int add2);
@WebMethod
public int multiply(int mul1, int mul2);
}
public int multiply(int mul1, int mul2) {
return mul1 * mul2;
}
}
/**
* Created with IntelliJ IDEA.
* User: Administrator
* Date: 14-3-10
* Time: 下午3:10
*/
public class CalclulatorPublisher {
public static void main(String[] args) {
Endpoint.publish("http://localhost:8080/test/calc", new Calculator());
//Endpoint.publish("http://10.3.18.44:8080/test/calc", new Calculator());
}
}[/code]
运行上面的这段代码,让你的webservice跑起来,接下来就可以使用Python来测试你的webservice代码了。
上面的代码跑起来后,你可以直接使用浏览器访问:
print client
sum_result = service.sum(10, 34)
print sum_result
print client.last_received()
multiply_result = service.multiply(5, 5)
print multiply_result
print client.last_received()
将上述代码保存成webservice.py文件,再修改一下可执行权限:
输出结果如下:
Service ( CalculatorService ) tns="http://xxx.com/wsdl"
Prefixes (1)
ns0 = "http://xxx.com/wsdl"
Ports (1):
(CalculatorPort)
Methods (2):
multiply(xs:int arg0, xs:int arg1, )
sum(xs:int arg0, xs:int arg1, )
Types (4):
multiply
multiplyResponse
sum
sumResponse
44
25
三、常见问题
注意,在执行上面的代码时,有可能提示:
OK。