编写jax-ws Web服务并在没有XSD的情况下生成WSDL [英] Write jax-ws web service and generate WSDL without XSD

查看:509
本文介绍了编写jax-ws Web服务并在没有XSD的情况下生成WSDL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在java上为tomcat应用服务器编写了一个简单的JAX-WS Web服务。

I wrote a simple JAX-WS web service for tomcat application server on java.

我有一个接口和实现类:


interface

I have one interface and on implementation class:
interface

@WebService(name = "myWs")
@SOAPBinding(style = Style.RPC)
public interface IMyWs {
    @WebMethod(operationName = "getUser")
    Response getUser(@WebParam(name = "phone", mode = Mode.IN) String phone);

}



实施

@WebService(endpointInterface = "ge.mari.IMyWs")
public class MyWs implements IMyWs {
    @Override
    public Response getUser(String phone) {
               // SOME CODE
        return response;
    }
}

我的问题是,在我的wsdl中文件响应类在xsd文件中定义。

这是我的wsdl文件的片段

My problem is that, in my wsdl file Response class is defined in xsd file.
This is the snippet from my wsdl file

<types>
<xsd:schema>
          <xsd:import namespace="http://ws.mari.ge/" schemaLocation="http://localhost:8080/MyServcie/MyWs?xsd=1">
</xsd:import>
</xsd:schema>
</types>

如何使Web服务生成WSDL文件中的所有类型而不是单独的XSD文件?

我应该更改任何配置或向我的网络服务添加一些注释吗?

How can I make web service to generate all types in WSDL file instead of separate XSD file?
Should I change any configuration or add some annotation to my web service?

推荐答案

您可以让JAX-WS使用

You can have JAX-WS insert the generated schema into your WSDL file by using the

-inlineSchemas

命令行开关。 [1]

command line switch. [1]

如果您在项目中使用Maven,则可以配置JAX-WS maven插件以对 inlineSchemas 执行相同操作执行配置中的配置元素如下:[2]

If you're using Maven in your project you can configure the JAX-WS maven plugin to do the same with the inlineSchemas configuration element in your execution configuration as follows: [2]

<plugin>
  <groupId>org.jvnet.jax-ws-commons</groupId>
  <artifactId>jaxws-maven-plugin</artifactId>
  <version>2.2</version>
  <executions>
    <execution>
      <id>SomeId</id>
      <goals>
        <goal>wsgen</goal>
      </goals>
      <phase>prepare-package</phase>
      <configuration>
        <sei>some.class.Name</sei>
        <genWsdl>true</genWsdl>
        <keep>true</keep>
        <resourceDestDir>some/target/dir</resourceDestDir>
        <inlineSchemas>true</inlineSchemas>
      </configuration>
    </execution>
  </executions>
</plugin>

不需要对Java类进行任何更改。

No changes to your Java class are necessary.

[1] http://jax-ws.java .net / nonav / 2.2.1 / docs / wsgen.html

[2] http://jax-ws-commons.java.net/jaxws-maven-plugin/wsgen-mojo.html

这篇关于编写jax-ws Web服务并在没有XSD的情况下生成WSDL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆