如何使用JAXBElement< String>在Web服务? [英] How to use JAXBElement<String> in Web Service?

查看:196
本文介绍了如何使用JAXBElement< String>在Web服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WCF开发一个可互操作的Web服务,我正在从Java客户端使用它。当我创建代理类时,它生成了所有getter和setter方法以及 JAXBElement< String> 字段。我在JDK API中搜索了这个并找到了构造函数:

I am developing an interoperable web service using WCF which I am consuming from a Java client. When I created the proxy class it generated all the getter and setter methods as well as a JAXBElement<String> field. I searched for this in the JDK API and found the constructor:

JAXBElement(QName name, Class<T> declaredType, Class scope, T value) 

我应该如何使用这个构造函数?请解释一下参数,如果互联网上有一个很好的教程描述它的使用,请告诉我。

How should I use this constructor? Please explain the parameters and let me know if there is a good tutorial on the Internet describing its use.

推荐答案

解决这个问题是的,您不需要创建单独的构造函数来创建 JAXBElement 。可以从 objectFactory.create ........()方法中检索受尊重的元素。假设您要在响应对象中创建并设置一些值,并且参数是 JAXBElement 类型,那么您需要这样做:

A solution this problem is, you do not need to create a seperate constructor for creating a JAXBElement. The respected element can be retrieved from objectFactory.create........() method. Suppose you want to create and set some value in response object, and argument is as of JAXBElement type, then you need to do this way:

someResponseObj.setMyValue(objectFactory.create.......()); 
/*method name that will be return a JAXBElement in setter()*/

注意:请检查 ObjectFactory 引用,因为生成的代码中可能有多个 ObjectFactory 类你需要引用与该包的类相关联的确切的一个。

Note: Please check the ObjectFactory reference because there can be multiple ObjectFactory classes in generated code so you need to refer the exact one which is associated to the class of that package.

这篇关于如何使用JAXBElement&lt; String&gt;在Web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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