草庐IT

java - JAX-WS 在生成 wsdl 时复制复杂类型

coder 2024-04-01 原文

我正在开发一个 Web 服务,其中包含多种方法,将相同的复杂数据类型作为输入。数据类型有 JAXB 注释和 setter 和 getter,Web 服务类有 JAX-WS 注释。

我的 service.java 文件的模板:

@WebService(serviceName = "ServiceWS")
public class SericeWS {

private static ServiceIF serviceImpl;

static {
    serviceImpl = new ServiceImpl();
}

public Result Method1(Credentials credentials) {
        @WebParam(name = "credentials") Credentials credentials) { 

    return serviceImpl.Method1(credentials);
}

    public Result Method2(Credentials credentials) {
        @WebParam(name = "credentials") Credentials credentials) { 

    return serviceImpl.Method2(credentials);
}

编辑:我的 Credentials.java 文件:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "name",
    "password"
})
@XmlRootElement(name = "Credentials")
public class Credentials implements MyBean {

    @XmlElement(required = true)
    protected String name;
    @XmlElement(required = true)
    protected String password;

    /**
     * Gets the value of the name property.
     * 
     * @return The name property of the credentials
     *     
     */
    public String getName() {
        return name;
    }

    /**
     * Sets the value of the name property.
     * 
     * @param value The name property of the credentials
     *     
     */
    public void setName(String value) {
       this.name = value;
    }

    /**
     * Gets the value of the password property.
     * 
     * @return The password property of the credentials
     *     
     */
    public String getPassword() {
        return password;
    }

    /**
     * Sets the value of the password property.
     * 
     * @param value The password property of the credentials
     *       
     */
    public void setPassword(String password) {
        this.password = password;
    }  
}

服务部署在 Tomcat 中,wsdl 是自动生成的。使用 wsimport 生成客户端 stub 时,我得到了 Credentials 类型(Credentials、Method1.Credentials 和 Method2.Credentials)的重复生成,即每个方法的不同(内部)类。

问题似乎是在生成 wsdl 和 schema 时出现的:

<xs:schema xmlns:tns="http://service.my.package.com/"            
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" 
targetNamespace="http://service.my.package.com/">
<xs:element name="Credentials">
 <xs:complexType>
  <xs:sequence>
   <xs:element name="name" type="xs:string"/>
   <xs:element name="password" type="xs:string"/>
  </xs:sequence>
 </xs:complexType>
</xs:element>  
....
<xs:complexType name="getLockBoxKeys">
 <xs:sequence>
  <xs:element name="credentials" minOccurs="0">
   <xs:complexType>
    <xs:sequence>
     <xs:element name="name" type="xs:string"/>
     <xs:element name="password" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
 </xs:element>    
 .....

我怎样才能使所有这些工作使我只有一个凭证定义?我对 Web 服务、JAX-WS 和 JAXB 很陌生,所以我不确定我的注释是否正确。

如有任何帮助,我们将不胜感激。

最佳答案

我不会给出解释所有规则的完整答案,因为我不记得/理解所有规则。

但我认为如果您将 name 元素添加到您的 @XMLType 注释中,您将获得您正在寻找的内容(或至少更进一步)。

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Credentials", propOrder = {
    "name",
    "password"
})
@XmlRootElement(name = "Credentials")
public class Credentials {

顺便说一句,您的原始 service.java 文件似乎没有粘贴得太干净(我认为有一些不正确的括号)让任何人都很难重新创建。

关于java - JAX-WS 在生成 wsdl 时复制复杂类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16078420/

有关java - JAX-WS 在生成 wsdl 时复制复杂类型的更多相关文章

  1. ruby - Infinity 和 NaN 的类型是什么? - 2

    我可以得到Infinity和NaNn=9.0/0#=>Infinityn.class#=>Floatm=0/0.0#=>NaNm.class#=>Float但是当我想直接访问Infinity或NaN时:Infinity#=>uninitializedconstantInfinity(NameError)NaN#=>uninitializedconstantNaN(NameError)什么是Infinity和NaN?它们是对象、关键字还是其他东西? 最佳答案 您看到打印为Infinity和NaN的只是Float类的两个特殊实例的字符串

  2. ruby - 检查方法参数的类型 - 2

    我不确定传递给方法的对象的类型是否正确。我可能会将一个字符串传递给一个只能处理整数的函数。某种运行时保证怎么样?我看不到比以下更好的选择:defsomeFixNumMangler(input)raise"wrongtype:integerrequired"unlessinput.class==FixNumother_stuffend有更好的选择吗? 最佳答案 使用Kernel#Integer在使用之前转换输入的方法。当无法以任何合理的方式将输入转换为整数时,它将引发ArgumentError。defmy_method(number)

  3. java - 等价于 Java 中的 Ruby Hash - 2

    我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/

  4. ruby-on-rails - s3_direct_upload 在生产服务器中不工作 - 2

    在Rails4.0.2中,我使用s3_direct_upload和aws-sdkgems直接为s3存储桶上传文件。在开发环境中它工作正常,但在生产环境中它会抛出如下错误,ActionView::Template::Error(noimplicitconversionofnilintoString)在View中,create_cv_url,:id=>"s3_uploader",:key=>"cv_uploads/{unique_id}/${filename}",:key_starts_with=>"cv_uploads/",:callback_param=>"cv[direct_uplo

  5. ruby - Ruby 有 `Pair` 数据类型吗? - 2

    有时我需要处理键/值数据。我不喜欢使用数组,因为它们在大小上没有限制(很容易不小心添加超过2个项目,而且您最终需要稍后验证大小)。此外,0和1的索引变成了魔数(MagicNumber),并且在传达含义方面做得很差(“当我说0时,我的意思是head...”)。散列也不合适,因为可能会不小心添加额外的条目。我写了下面的类来解决这个问题:classPairattr_accessor:head,:taildefinitialize(h,t)@head,@tail=h,tendend它工作得很好并且解决了问题,但我很想知道:Ruby标准库是否已经带有这样一个类? 最佳

  6. ruby - 查找字符串中的内容类型(数字、日期、时间、字符串等) - 2

    我正在尝试解析一个CSV文件并使用SQL命令自动为其创建一个表。CSV中的第一行给出了列标题。但我需要推断每个列的类型。Ruby中是否有任何函数可以找到每个字段中内容的类型。例如,CSV行:"12012","Test","1233.22","12:21:22","10/10/2009"应该产生像这样的类型['integer','string','float','time','date']谢谢! 最佳答案 require'time'defto_something(str)if(num=Integer(str)rescueFloat(s

  7. ruby-on-rails - 在 Rails 开发环境中为 .ogv 文件设置 Mime 类型 - 2

    我正在玩HTML5视频并且在ERB中有以下片段:mp4视频从在我的开发环境中运行的服务器很好地流式传输到chrome。然而firefox显示带有海报图像的视频播放器,但带有一个大X。问题似乎是mongrel不确定ogv扩展的mime类型,并且只返回text/plain,如curl所示:$curl-Ihttp://0.0.0.0:3000/pr6.ogvHTTP/1.1200OKConnection:closeDate:Mon,19Apr201012:33:50GMTLast-Modified:Sun,18Apr201012:46:07GMTContent-Type:text/plain

  8. java - 从 JRuby 调用 Java 类的问题 - 2

    我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www

  9. java - 我的模型类或其他类中应该有逻辑吗 - 2

    我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我

  10. java - 什么相当于 ruby​​ 的 rack 或 python 的 Java wsgi? - 2

    什么是ruby​​的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht

随机推荐