java JAX-WS 在不同的 URL 中有 XSD 模式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16030574/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 21:40:31  来源:igfitidea点击:

JAX-WS has XSD schema in different URL

javaweb-servicesxsdwsdljax-ws

提问by Mawia

I made a small web service using JAX-WS. The WSDL file has TYPES element like this.

我使用 JAX-WS 创建了一个小型 Web 服务。WSDL 文件有这样的 TYPES 元素。

<types>
  <xsd:schema>
  <xsd:import namespace="http://ws.poc.mawia/" schemaLocation="http://localhost:777/ws/hello?xsd=1"/>
  </xsd:schema>
</types>

The URL for web service is http://localhost:777/ws/hello?wsdland XSD is http://localhost:777/ws/hello?xsd=1. The XSD Schema file in different location has the data type definitions like this.

Web 服务的 URL 是http://localhost:777/ws/hello?wsdl,XSD 是http://localhost:777/ws/hello?xsd=1。不同位置的 XSD Schema 文件具有这样的数据类型定义。

...
 ...
    <xs:complexType name="student">
     <xs:sequence>
     <xs:element name="name" type="xs:string" minOccurs="0"/>
     <xs:element name="rollNo" type="xs:int"/>
     </xs:sequence>
    </xs:complexType>
  ...
 ...

Most of the WSDL files I have seen usually has the complete XSD definitions inside the WSDL file itself but JAX-WS is placing it in a different location.

我见过的大多数 WSDL 文件通常在 WSDL 文件中都有完整的 XSD 定义,但 JAX-WS 将它放在不同的位置。

Is this how it should be? How can I configure JAX-WS to place all XSD definitions in one WSDL file?

这是应该的吗?如何配置 JAX-WS 以将所有 XSD 定义放在一个 WSDL 文件中?

回答by joergl

Is this how it should be?

这是应该的吗?

Separating the XSD from the WSDL is the default behaviour in JAX-WS, and you shouldn't need to worry too much about it. Up-to-date WS frameworks (including WCF) are generally able to handle that. Depending on the size of the XSD, importing it might make the WSDL more readable for a human. For a small web service it would certainly be easier to have an embedded schema, but it's also not too much of a problem to import it.

将 XSD 与 WSDL 分开是 JAX-WS 中的默认行为,您无需过多担心。最新的 WS 框架(包括 WCF)通常能够处理这个问题。根据 XSD 的大小,导入它可能会使 WSDL 对人类更具可读性。对于小型 Web 服务,拥有嵌入式模式肯定会更容易,但导入它也不是什么大问题。

How can I configure JAX-WS to place all XSD definitions in one WSDL file?

如何配置 JAX-WS 以将所有 XSD 定义放在一个 WSDL 文件中?

I don't know of a direct way to make the runtime embed the schema in the WSDL, but there is a workaround through which you can achieve this:

我不知道让运行时在 WSDL 中嵌入模式的直接方法,但有一种解决方法可以实现这一点:

  1. Publish your endpoint and save the WSDL and the XSD
  2. Manually copy the content of the XSD into the typessection of the WSDL and replace the schema import there
  3. Save the merged WSDL file somewhere where your application can access it as a resource
  4. Have your web service load the merged WSDL. This will stop the dynamic generation however, you will have to manually update the WSDL each time you make changes to the interface
  1. 发布您的端点并保存 WSDL 和 XSD
  2. 手动将 XSD 的内容复制到typesWSDL的部分并替换那里的模式导入
  3. 将合并的 WSDL 文件保存在您的应用程序可以将其作为资源访问的某个位置
  4. 让您的 Web 服务加载合并的 WSDL。这将停止动态生成,但是,每次对界面进行更改时,您都必须手动更新 WSDL

You can implement 4. by customizing the @WebServiceannotation. This might look somewhat like this:

4. 自定义@WebService注解即可实现。这可能看起来有点像这样:

@WebService( wsdlLocation = "MyWebService.wsdl")
public class MyWebService { .... }

回答by Ashay Batwal

There isn't anything wrong with your approach. WSDL pointing to another wsdl using URL is fine.

你的方法没有任何问题。使用 URL 指向另一个 wsdl 的 WSDL 很好。

If you don't want it, mention the wsdl location using wsdlLocation attribute of @WebService annotation. But again with this approach you will have to modify wsdl manually.

如果您不想要它,请使用 @WebService 注释的 wsdlLocation 属性提及 wsdl 位置。但是再次使用这种方法,您将不得不手动修改 wsdl。