How to change the name of a WebService using CXF?

不想你离开。 提交于 2020-01-25 01:29:05

问题


We have a WebService, let´s call it CarLoans, which is generated by cxf based on a WSDL file. The WSDL is retrieved using the maven-resources-plugin from an external dependency. The cxf-codegen-plugin has a bindings file which we use to prefix various other elements with, for example the request and response object to the WebService. Let`s assume that we want the request and response objects to be prefixed WS and CarLoans postfixed EndPoint. How do we configure this using the bindings.xml file? The resulting java code should look roughly like this (excluding irrelevant annotations etc):

@WebService(targetNamespace="http://url.com/", name="CarLoansPortType")
public interface CarLoansPortType {
  public WSCarLoansResponse getCarLoans(@WebParam(name = "request") WSCarLoansRequest request)
}

回答1:


I found an interesting link in the apache mail archives - http://mail-archives.apache.org/mod_mbox/cxf-users/201202.mbox/%3CCAMHV5gYe8VQDoBfKdEP9nrg-VXy9FnA9BL_4oqpE_zKC2=-x3w@mail.gmail.com%3E

The relevant code is pasted below:

<jaxws:bindings 
  xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <jaxws:bindings node="wsdl:definitions/wsdl:portType[@name='CREATE_RECIPE']">
      <jaxws:class name="CreateRecipeSEI"/>
  </jaxws:bindings>
</jaxws:bindings>

So basically it should be fairly easy to do. I´m experiencing some local problems with getting the XPATH expression to work, but this definitely seems to be what we were looking for.




回答2:


I would not recommend doing that.

What you are using is called the 'Contract First' approach, where the web service and its data types are defined in a WSDL file. Then tools are used to generate appropriate code in a given programming language.

However, if you are the author of the WSDL in question, you need to modify the name of the data-types in WSDL. Look for data-types definitions under the <types> element. WSDLs are complex and you should modify them only if you know what you are doing.



来源:https://stackoverflow.com/questions/20245639/how-to-change-the-name-of-a-webservice-using-cxf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!