如何在JAX-WS服务实现中获取@WebMethod的操作?

时间:2014-10-15 06:16:46

标签: java web-services

我在Java中实现了一个使用JAX-WS RI 2.2.8生成的服务接口。

我有以下几行:

@WebService(name = "IService", targetNamespace = "http://tempuri.org/")
@XmlSeeAlso({
    ObjectFactory.class
})
public interface IService {

@WebMethod(operationName = "PersonList", action = "http://tempuri.org/IService/PersonList")
@WebResult(name = "PersonListResult", targetNamespace = "http://tempuri.org/")
@RequestWrapper(localName = "PersonList", targetNamespace = "http://tempuri.org/", className = "org.test.wsdl.PersonList")
@ResponseWrapper(localName = "PersonListResponse", targetNamespace = "http://tempuri.org/", className = "org.test.wsdl.PersonListResponse")
public PersonListResponseX personList();

我想做什么,我想得到这个:

action = " http://tempuri.org/IService/PersonList"

并在我的服务实现的SoapActionCallback中使用它。

@Service
public class NewService implements IService {

private final ObjectFactory of = new ObjectFactory();

@Autowired
private WebServiceTemplate webServiceTemplate;

@Override
public PersonListResponseX personList() {

// URL I need is http://tempuri.org/IService/PersonList
    SoapActionCallback callback = new SoapActionCallback(URL);
    PersonList personList = of.createPersonList();

    PersonListResponse personListResponse = (PersonListResponse) webServiceTemplate.marshalSendAndReceive(personList, callback);
    JAXBElement<PersonListResponseX> value = personListResponse.getPersonListResult();

}

1 个答案:

答案 0 :(得分:0)

试试这个:

    WebMethod webmethod = <Soap class Here>.class.getAnnotation(WebMethod.class);
    String action = webmethod.action();