日期:2014-05-17  浏览次数:21416 次

求助,关于webservice客户端调用的奇怪问题
  情况是这样的,开发了一个webservice服务端,并用cxf生成客户端,在本地测试调用服务端没有问题,打包发送到测试现场,客户端掉不通了,但能正常访问wsdl,说明服务端正常发布了,错误信息如下:

Caused by: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:93)
at org.apache.cxf.jaxws.ServiceImpl.initializePorts(ServiceImpl.java:203)
at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:147)
... 49 more
Caused by: javax.wsdl.WSDLException: WSDLException (at /html): faultCode=INVALID_WSDL: Expected element '{http://schemas.xmlsoap.org/wsdl/}definitions'.
at com.ibm.wsdl.xml.WSDLReaderImpl.checkElementName(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.parseDefinitions(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:237)
at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:186)
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:91)


客户端调用代码如下:

private String getBaseItemService(String dimName,String orgCode,String userName,String password,String ip){
URL url;
String xml = "";
try {
String urlPath = ip + "/dna_ws/DataHandleServiceImpl?wsdl";
url = new URL(urlPath);
DataHandleServiceImpl service = new DataHandleServiceImpl(url);
IDataHandleService iservice = service.getDataHandleServiceImplPort();
xml = iservice.getBaseDataItemsByCode(orgCode,userName,password,dimName.toUpperCase());
} catch (MalformedURLException e) {
xml = e.getMessage();
e.printStackTrace();
}
return xml;
}


关于“ WSDLException (at /html): faultCode=INVALID_WSDL”我在网上也没有查出个所以然,调用的时候也加了"?wsdl"后缀的,不知道有没有大侠遇到过此类问题,求帮助。

------解决方案--------------------
早前写webservice遇到的错误 

org.xml.sax.SAXException: Bad envelope tag: definitions
刚开始以为是报文出错,格式有问题,检查过后感觉没有问题。

后来检查WSDL,果然是WSDL搞错了

正确:http://127.0.0.1:7001/crmService/services/agentInterface
错误:http://127.0.0.1:7001/crmService/services/agentInterface?wsdl
楼主去掉 ?wsdl 试试看