package com.jboss.webservice;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
/**
* This is a webservice class exposing a method called greet which takes a input
* parameter and greets the parameter with hello.
*
* @author Ji-Woong Choi
*/
/*
* @WebService indicates that this is webservice interface and the name
* indicates the webservice name.
*/
@WebService(name = "Hello", targetNamespace="http://client.jboss.com/", serviceName="GreetService")
/*
* @SOAPBinding indicates binding information of soap messages. Here we have
* document-literal style of webservice and the parameter style is wrapped.
*/
//@SOAPBinding(style = SOAPBinding.Style.RPC, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
@SOAPBinding(style = SOAPBinding.Style.RPC, use = SOAPBinding.Use.LITERAL)
public class Hello {
/**
* This method takes a input parameter and appends "Hello" to it and returns
* the same.
*
* @param name
* @return
*/
@WebMethod
public String greet(@WebParam(name = "name")
String name) {
System.out.println("JBoss Web Service was invoked by " + name);
return "Hello!, " + name;
}
}
Web Service Annotation을 이용하여 필요한 메소드들을 구성합니다.
2. Web.xml 파일을 편집합니다. 본 예제에서는 servlet style을 이용하여 처리합니다.
다른 방법으로는 EJB를 이용하여 port proxy를 remote stub을 이용하는 방법이 있지만 web이 테스트하기 보다 단순하므로 이 예제를 이용하겠습니다.
3. 서버에 디플로이 후 Web Service에 대한 deploy상태를 확인합니다.
http://localhost:8080/jbossws/ 라고 입력하면 웹서비스 리스트를 확인할 수 있습니다.
4. WSDL의 디플로이된 상태를 확인합니다.
5. 이제 클라이언트 코드를 작성합니다. 여기서는 DII방식(Dynamic Invocation Interface) 방식을 이용하여 작성합니다.
위의 코드를 실행하면 서버에 System console에 적은 내용이 찍히게 되며, 클라이언트에서 응답을 받을 수 있습니다.