使用 JAX-WS 使用 ASP.net Web 服务,获取“指定的类型是抽象的”
我正在尝试为我们使用 ASP.net 构建的 SOAP Web 服务创建一个快速示例 Java 客户端。
Web 服务消息模式使用了许多抽象类及其实现,例如 DeviceIdentifier(抽象)、SerialNumber 和 ProductNumber(这些是说明问题的假设示例)
我使用 wsimport 创建客户端代理来使用 Web 服务来自我的java代码:
wsimport -extension -s c:\theservice -d c:\theservice -p theservice http://server/theservice?wsdl
然后我按如下方式组装消息:
GetDeviceReq request = new GetProductReq();
DeviceIdentifier id = new SerialNumber();
((SerialNumber)id).setUnitIdentifier(id);
GetDeviceResp response = service.GetDevice(request);
代码完美编译并执行。但是,我从 ASP.net Web 服务获得了 SOAPFaultException,其中包含以下消息:
The specified type is abstract: name='DeviceIdentifier', namespace='http://bogus', at <unitIdentifier xmlns='http://bogus'>.
我了解错误消息的含义,但我不知道为什么会在这种情况下发生?我怀疑这可能与 wsimport 工具生成代理代码的方式有关?
I am trying to create a quick sample Java client for a SOAP web service we have built with ASP.net.
The web service message schema makes use of many abstract classes with implementations of those, e.g. DeviceIdentifier (abstract), with SerialNumber and ProductNumber (these are hypothetical examples to illustrate the question)
I used wsimport to create the client side proxy to consume the web service from my java code:
wsimport -extension -s c:\theservice -d c:\theservice -p theservice http://server/theservice?wsdl
I then assemble the message as follows:
GetDeviceReq request = new GetProductReq();
DeviceIdentifier id = new SerialNumber();
((SerialNumber)id).setUnitIdentifier(id);
GetDeviceResp response = service.GetDevice(request);
The code compiles perfectly and executes. However, I obtain a SOAPFaultException with the following message from the ASP.net web service:
The specified type is abstract: name='DeviceIdentifier', namespace='http://bogus', at <unitIdentifier xmlns='http://bogus'>.
I understand what the error message means, but I am running out of ideas as to why its happening in this case? I suspect it may have something to do with the way the wsimport tool generated the proxy code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我解决了我自己的问题!
我使用的是 JDK 6,其中包括 JAX-WS 2.0。看起来这个版本不会自动用 @XmlSeeAlso 属性装饰抽象类。我手动修改了代理代码以在抽象类上包含这些属性。对于上面给出的示例:
wsimport 生成的代码如下所示:
然后我添加了 @XmlSeeAlso:
这类似于 System.Xml 中 C#/.Net 中的 XmlInclude 属性
看起来这个问题已在较新的版本中得到修复JAX-WS 按照 本文。
I solved my own problem!
I am using JDK 6, which includes JAX-WS 2.0. It looks like this version doesnt automatically decorate abstract classes with @XmlSeeAlso attributes. I manually modified the proxy code to include these attributes on the abstract classes. For the example give above:
The code generated by wsimport looks like this:
I then added the @XmlSeeAlso:
This is similar to the XmlInclude attribute in C#/.Net in System.Xml
It looks like this problem has been fixed in more recent versions of JAX-WS as per this article.