简体   繁体   English

XML阅读器错误:调用Web服务时出现意外的字符内容异常

[英]XML reader error: unexpected character content exception while invoking webservice

Am trying to invoke a public web-service using a java client but am getting the following exception: 我正在尝试使用Java客户端调用公共Web服务,但遇到以下异常:

deserialization error: XML reader error: unexpected character content: "<?xml version="1.0" ?>
<rankedTermCandidates 
  xmlns="http://www.nactem.ac.uk/xsd/termine" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://www.nactem.ac.uk/xsd/termine http://www.nactem.ac.uk/software/termine/webservice/termine.xsd" 
  >

Am not able to find out what I am doing wrong. 无法找出我在做什么错。 Am tempted to move to a .NET client{am ac# programmer} but would like to know what I am doing wrong here. 我很想迁移到.NET客户端{ac程序员#},但想知道我在这里做错了什么。

The method calling the webservice is : 调用webservice的方法是:

    private String InvokeNactemWebService(String textToParse) throws Exception
{

String wsdlURL = "http://www.nactem.ac.uk/software/termine/webservice/termine.wsdl";
URL url = new URL(wsdlURL);
String targetNamespace = "urn:termine";
String   serviceName = "termine";
String      portName = "termine_porttype";
String operationName = "analyze";
QName    serviceQN   = new QName(targetNamespace, serviceName);
QName       portQN   = new QName(targetNamespace, portName);
QName  operationQN   = new QName(targetNamespace, operationName);

String parseResult = "";

try
{
      ServiceFactory serviceFactory = ServiceFactory.newInstance();
      Service service = serviceFactory.createService(url, serviceQN);

      Call call = (Call) service.createCall();
      call.setProperty(Call.ENCODINGSTYLE_URI_PROPERTY, "");
      call.setProperty(Call.OPERATION_STYLE_PROPERTY, "rpc");
      call.setTargetEndpointAddress("http://www.nactem.ac.uk:9000/termine");


      call.setPortTypeName(portQN);
      call.setOperationName(operationQN);

      call.removeAllParameters();
      call.addParameter("src",           XMLType.XSD_STRING, ParameterMode.IN);
      call.addParameter("input_format",  XMLType.XSD_STRING, ParameterMode.IN);
      call.addParameter("output_format", XMLType.XSD_STRING, ParameterMode.IN);
      call.addParameter("stoplist",      XMLType.XSD_STRING, ParameterMode.IN);
      call.addParameter("filter",        XMLType.XSD_STRING, ParameterMode.IN);


      Object[] inParams = new Object[] {textToParse, "", "xml", "", ""};

      Object result = call.invoke(inParams);
      //parseResult = (String) call.invoke(inParams);
      //System.out.println(call.invoke(inParams));
      return parseResult;
    }
    catch (Exception e)
    {
        e.printStackTrace();
        Debug.println(e.getMessage(), e.getStackTrace().toString());
    }

    return parseResult;

}

change 更改

Service service = serviceFactory.createService(url, serviceQN);

to

Service service = serviceFactory.createService(serviceQN);

- -

so that you can add this to your code.. 以便您可以将其添加到您的代码中。

call.setReturnType(XMLType.XSD_STRING);

I suspect there's a byte-order-mark in your XML response. 我怀疑您的XML响应中有字节顺序标记 See this SO question for further details. 有关更多详细信息,请参见此SO问题 Capturing the response using Wireshark or similar will indicate what's going on. 使用Wireshark或类似工具捕获响应将指示发生了什么。

If you do have a BOM, I suspect you can install a servlet filter to intercept the response before the webservice XML parsing code, and remove the BOM from the raw response before passing it forward. 如果您确实有BOM,我怀疑您可以在Web服务XML解析代码之前安装servlet过滤器以拦截响应,并在将原始BOM传递之前将其从原始响应中删除。

I might be a little late, but I believe all you need to do is set the return type that you'll be expecting, like: 我可能会晚一点,但是我相信您需要做的就是设置您期望的返回类型,例如:

call.setReturnType(XMLType.XSD_STRING);

This did the trick for my TerMine client :) 这为我的TerMine客户提供了诀窍:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JAX-WS出错由于异常而无法创建SOAP消息:XML reader错误:WstxUnexpectedCharException:意外字符&#39;[&#39; - Error with JAX-WS Couldn't create SOAP message due to exception: XML reader error: WstxUnexpectedCharException: Unexpected character '[' 在Android中调用API时出现XML错误 - XML error while invoking an API in Android 生成Web服务客户端时Apache发生意外的子元素异常 - Apache Unexpected subelement exception while generating a webservice client open_reader() 中的意外异常 - Unexpected Exception in open_reader() 调用Web服务时绕过HTTPS证书验证 - Bypass HTTPS certificate validation while invoking webservice 调用WebServices时org.xml.sax.SAXParseException错误 - org.xml.sax.SAXParseException Error while invoking WebServices org.xml 解析 XML.sax.SAXParseException 时出现异常:元素的内容必须由格式正确的字符数据或标记组成 - org.xmlGetting exception while parsing XML.sax.SAXParseException: The content of elements must consist of well-formed character data or markup Android XML阅读器出错 - Error with Android XML reader Java XML 读卡器错误 - Java XML Reader error jackson解析器异常:意外字符 - jackson parser exception: unexpected Character
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM