我正在尝试使用以下代码调用Web服务:
/*
* A sample Java code for the Termine Web Service.
*/
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.rpc.*;
import javax.xml.rpc.encoding.XMLType;
public class termine
{
public static void main(String[] args) throws Exception
{
String sentence = "Technical terms are important for knowledge mining, especially in the bio-medical area where vast amount of documents are available.";
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);
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, "wrapped");
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[] {sentence, "", "xml", "", ""};
call.setReturnType(XMLType.XSD_STRING);
System.out.println(call.invoke(inParams));
}
catch (Exception e) {e.printStackTrace();}
}
}
但是,我收到以下错误。
javax.xml.rpc.ServiceException:找不到提供者com.sun.xml.rpc.client.ServiceFactoryImpl 在javax.xml.rpc.FactoryFinder.newInstance(FactoryFinder.java:44) 在javax.xml.rpc.FactoryFinder.find(FactoryFinder.java:137) 在javax.xml.rpc.ServiceFactory.newInstance(ServiceFactory.java:58) 在com.ivita.termExtraction.termine.main(termine.java:31)
通过阅读网络上的类似问题,我得到的印象是我没有使用正确的库。在我的pom.xml中,我提供了以下依赖项:
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxrpc-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis-jaxrpc</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.11.0</version>
</dependency>
你能帮我解决这个问题吗? 谢谢!
答案 0 :(得分:1)
将以下依赖项添加到我的pom.xml解决了这个问题(部分原因是其他依赖项似乎仍然缺失)。
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>