JAX-WS在不同的URL中具有XSD架构 [英] JAX-WS has XSD schema in different URL

查看:59
本文介绍了JAX-WS在不同的URL中具有XSD架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用JAX-WS制作了一个小型Web服务. WSDL文件具有这样的TYPES元素.

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

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

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

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

...
 ...
    <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>
  ...
 ...

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

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.

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

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

推荐答案

这应该是吗?

Is this how it should be?

将XSD与WSDL分开是JAX-WS的默认行为,您不必为此担心太多.最新的WS框架(包括WCF)通常可以处理此问题.根据XSD的大小,导入它可能会使WSDL对人类更具可读性.对于小型Web服务,拥有嵌入式模式当然会更容易,但是导入它也不是太大的问题.

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.

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

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

我不知道使运行时将模式嵌入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:

  1. 发布端点并保存WSDL和XSD
  2. 手动将XSD的内容复制到WSDL的types部分,并替换在那里的架构导入
  3. 将合并的WSDL文件保存在应用程序可以将其作为资源访问的位置
  4. 让您的Web服务加载合并的WSDL.这将停止动态生成,但是,每次更改界面时,您都必须手动更新WSDL
  1. Publish your endpoint and save the WSDL and the XSD
  2. Manually copy the content of the XSD into the types section 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

您可以通过自定义@WebService批注来实现4.这可能看起来像这样:

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

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

这篇关于JAX-WS在不同的URL中具有XSD架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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