简体   繁体   中英

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:

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.

The method calling the webservice is :

    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. See this SO question for further details. Capturing the response using Wireshark or similar will indicate what's going on.

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.

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM