使用javax.xml.namespace.Qname和javax.xml.ws.handler.PortInfo的Classcast异常

问题描述 投票:3回答:1

我使用IntelliJ连接到外部WSDL。

在连接到WSDL并生成我的Java类之后,我试图从服务获得响应。

该服务并不复杂,只是简单的“是”,“否”和“不正确”的消息响应。

但是我得到了一个涉及PortInfoQname的类演员异常。

方法列表调用如下。

 Service helloService = Service.create(
      helloWsdlUrl, 
      new QName(nameSpaceUri, serviceName));

 List list = helloService.getHandlerResolver().getHandlerChain(
      (PortInfo) new QName(nameSpaceUri, portName));

 list.add(new HandlerInfo((Class) null, (Map)null, (QName[])null));

我得到的错误信息是:

Exception in thread "main" java.lang.ClassCastException: 
javax.xml.namespace.QName cannot be cast to javax.xml.ws.handler.PortInfo
at Client.main(Client.java:37)

picture of portinfo removed

任何帮助将不胜感激。

谢谢

java soap port jax-ws wsdl2java
1个回答
1
投票

你的问题是,QName无法投射到PortInfo。以下代码生成错误:

(PortInfo) new QName(...)

你为什么要这样演员? getHandlerChain()应该能够接受QName实例。

© www.soinside.com 2019 - 2024. All rights reserved.