javax.xml.ws.WebServiceException:未定义的端口类型Java Struts SOAP WSDL

时间:2012-11-16 13:20:30

标签: java soap wsdl struts

好吧我真的有一个奇怪的问题,我今天在谷歌和雅虎寻找近4个小时的解决方案。我拼命寻找解决方案。

public static String [] checkCardAccount(String cardNumber, String cardIssuer, String securityNumber){

        URL url = null;
        try {
            url = new URL("http://localhost:8999/bankcard?wsdl");
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

        QName qname = new QName("http://server.bcard.soap.com/","BankCardImplService");

        Service service = Service.create(url,qname);

        BankCard bankcard = service.getPort(BankCard.class);

        return bankcard.getCardClientData(cardNumber, cardIssuer);
    }

上面的代码是我访问SOAP服务的客户端,它确实可以在独立的Java应用程序中运行,但是当我将它嵌入到我的Java Struts应用程序时,它会在下面显示以下错误

  

javax.xml.ws.WebServiceException:未定义的端口类型:   {http://bankcard.api.com/ }BankCard at   com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:349)     在   com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:355)     在javax.xml.ws.Service.getPort(Service.java:161)at   com.api.bankcard.BankCardClient.checkCardAccount(BankCardClient.java:25)     在com.action.CardregAction.execute(CardregAction.java:18)at   org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)     在   org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)     在   org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)     在   org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)     在   org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)     在   org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)     在   org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)     在   org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)     在   org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:637)at   javax.servlet.http.HttpServlet.service(HttpServlet.java:717)at at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)     在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)     在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)     在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)     在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)     在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)     在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)     在   org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)     在   org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process(Http11Protocol.java:588)     在   org.apache.tomcat.util.net.JIoEndpoint $ Worker.run(JIoEndpoint.java:489)     在java.lang.Thread.run(Thread.java:662)

现在我真的看到问题是目标命名空间,因为当我更改它时,错误会更改为表示有效服务为{http://bankcard.api.com/}BankCard

我出错的地方?此代码在Java Application上独立运行,但不在我的Java Struts Web应用程序中运行

2 个答案:

答案 0 :(得分:6)

在实现类的@WebService注释中给出endpointIneterface,如果你不提供端点接口,你必须在使用getPort方法时提到完全限定的端口名。

service.getPort( “PortQName”,BankCard.class);

答案 1 :(得分:1)

您需要使用BankCardImpl@WebService(name="BankCard")课程添加注释 然后,您可以使用service.getPort(BankCard.class);

如果您只是使用@WebService对其进行注释或者为其指定了其他名称,那么您需要向getPort()方法提供更多信息:

替换

BankCard bankcard = service.getPort(BankCard.class);

QName port_name = new QName("http://server.bcard.soap.com/","BankCardImplPort");
BankCard bankcard = service.getPort(port_name, BankCard.class);