[英]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.