开发者

using annotations with spring to access webservice

I need to access a webservice by using spring JaxWsPortProxyFactoryBean.开发者_如何转开发 i can wire it in a context xml and use it. are there any way to use that 'webservice' with only using annotations? i am using apache cxf and spring mvc 3.

baseline is i need to access a webservice without using xml configurations.is this possible? i saw some annotations like @WebMethod and @WebMethod but i don't know how to use it properly.

can anyone pointed me to an example. appreciate your help.

my WS url - http://localhost:8080/test.asmx/HelloWorld


I found the solution. please refer below.

JaxWsPortProxyFactoryBean jaxWsPortProxyFactoryBean = new JaxWsPortProxyFactoryBean();
String URI = "http://localhost:8080/service";
try {

    jaxWsPortProxyFactoryBean.setWsdlDocumentUrl(new URL(URI+"?wsdl"));
    jaxWsPortProxyFactoryBean.setServiceInterface(myIService.class);
    jaxWsPortProxyFactoryBean.setPortName(PORT);
    jaxWsPortProxyFactoryBean.setNamespaceUri(URI);
    jaxWsPortProxyFactoryBean.setServiceName(SERVICE_NAME);
    logger.debug("WSDL - "+jaxWsPortProxyFactoryBean.getWsdlDocumentUrl());
    jaxWsPortProxyFactoryBean.afterPropertiesSet();

} catch (Exception e) {
    logger.error("Error occured while connecting to the TW web service -",e);
}

Please refer Accessing web services using JAX-WS to get more information about the port and URI.

Service Interface -

     public interface testService {
@WebMethod(operationName = "myOperations",  action = "")
@WebResult(name = "errorCode",targetNamespace = "")

public String testWebService(
    @WebParam(name = "studentId", targetNamespace = "", mode = Mode.IN) Integer studentId,
    @WebParam(name = "studenName", targetNamespace = "", mode = Mode.IN) String studenName);
    }

myOperations - is the operation that you need to access in the webService

errorCode - is the return value from the webservice

studentId , studentName - are the parameters that you need to send to the webservice.

I got stuck how to figure out to map more than one attribute as webResults. I posted this question and still didn't have any luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜