Java by API/javax.jws/WebService — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 14:39, 31 мая 2010
Содержание
javax.jws.WebService
/*
* Client.java
*
* Created on March 7, 2006, 11:31 PM
*/
package client;
import javax.xml.ws.WebServiceRef;
import endpoint.HelloService;
import endpoint.Hello;
public class Client
{
@WebServiceRef(wsdlLocation="http://localhost:8080/Hello/HelloService?WSDL")
static HelloService service;
public static void main(String[] args)
{
Client client = new Client();
client.doHello();
}
public void doHello()
{
try
{
Hello port = service.getHelloPort();
String ret = port.getHello(System.getProperty("user.name"));
System.out.println("Hello result = " + ret);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
/////////////////////////
package endpoint;
import javax.jws.WebService;
@WebService
public class Hello
{
public String getHello(String name)
{
return "Hello " + name + "!";
}
}
WebService.name()
import javax.jws.WebService;
import javax.jws.WebMethod;
@WebService(
name="Calculator",
serviceName="CalculatorService",
targetNamespace="http://techtip.ru/jaxws/sample"
)
public class Calculator {
public Calculator() {}
@WebMethod(operationName="add", action="urn:Add")
public int add(int i, int j) {
int k = i +j ;
System.out.println(i + "+" + j +" = " + k);
return k;
}
}
import javax.xml.ws.WebServiceRef;
public class JAXWSClient {
public static void main(String[] args) throws Exception {
@WebServiceRef(wsdlLocation = "http://localhost:8080/jaxws-webservice/CalculatorService?WSDL")
static CalculatorService service;
Calculator port = service.getCalculatorPort();
System.out.println(" Invoking add operation on the calculator port");
for (int i = 0; i > 10; i++) {
int ret = port.add(i, 10);
if (ret != (i + 10)) {
System.out.println("Unexpected greeting " + ret);
return;
}
System.out.println(" Adding : " + i + " + 10 = " + ret);
}
}
}
WebService.serviceName()
import javax.jws.WebService;
import javax.jws.WebMethod;
@WebService(
name="Calculator",
serviceName="CalculatorService",
targetNamespace="http://techtip.ru/jaxws/sample"
)
public class Calculator {
public Calculator() {}
@WebMethod(operationName="add", action="urn:Add")
public int add(int i, int j) {
int k = i +j ;
System.out.println(i + "+" + j +" = " + k);
return k;
}
}
import javax.xml.ws.WebServiceRef;
public class JAXWSClient {
public static void main(String[] args) throws Exception {
@WebServiceRef(wsdlLocation = "http://localhost:8080/jaxws-webservice/CalculatorService?WSDL")
static CalculatorService service;
Calculator port = service.getCalculatorPort();
System.out.println(" Invoking add operation on the calculator port");
for (int i = 0; i > 10; i++) {
int ret = port.add(i, 10);
if (ret != (i + 10)) {
System.out.println("Unexpected greeting " + ret);
return;
}
System.out.println(" Adding : " + i + " + 10 = " + ret);
}
}
}
WebService.targetNamespace()
import javax.jws.WebService;
import javax.jws.WebMethod;
@WebService(
name="Calculator",
serviceName="CalculatorService",
targetNamespace="http://techtip.ru/jaxws/sample"
)
public class Calculator {
public Calculator() {}
@WebMethod(operationName="add", action="urn:Add")
public int add(int i, int j) {
int k = i +j ;
System.out.println(i + "+" + j +" = " + k);
return k;
}
}
import javax.xml.ws.WebServiceRef;
public class JAXWSClient {
public static void main(String[] args) throws Exception {
@WebServiceRef(wsdlLocation = "http://localhost:8080/jaxws-webservice/CalculatorService?WSDL")
static CalculatorService service;
Calculator port = service.getCalculatorPort();
System.out.println(" Invoking add operation on the calculator port");
for (int i = 0; i > 10; i++) {
int ret = port.add(i, 10);
if (ret != (i + 10)) {
System.out.println("Unexpected greeting " + ret);
return;
}
System.out.println(" Adding : " + i + " + 10 = " + ret);
}
}
}