我一直在尝试使用Eclipse,Tomcat 8和Axis来实现一个相当复杂的Web服务时遇到各种问题。这是我第一次使用Web服务,因此我决定开始搞一些更简单的事情,以确保我知道自己在做什么。这是我目前正在Eclipse中用于从中生成服务的WSDL。
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.example.org/WeatherService/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
name="WeatherService"
targetNamespace="http://www.example.org/WeatherService/">
<wsdl:types>
<xsd:schema targetNamespace="http://www.example.org/WeatherService/">
<xsd:element name="GetCurrentTemperatureRq">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="city" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="GetCurrentTemperatureRs">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="temperature" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="GetCurrentTemperatureRq">
<wsdl:part element="tns:GetCurrentTemperatureRq" name="parameters"/>
</wsdl:message>
<wsdl:message name="GetCurrentTemperatureRs">
<wsdl:part element="tns:GetCurrentTemperatureRs" name="parameters"/>
</wsdl:message>
<wsdl:portType name="WeatherServicePortType">
<wsdl:operation name="GetCurrentTemperature">
<wsdl:input message="tns:GetCurrentTemperatureRq"/>
<wsdl:output message="tns:GetCurrentTemperatureRs"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="WeatherServiceSOAP" type="tns:WeatherServicePortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetCurrentTemperature">
<soap:operation soapAction="http://www.example.org/WeatherService/GetCurrentTemperature"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="WeatherService">
<wsdl:port binding="tns:WeatherServiceSOAP" name="WeatherServiceSOAP">
<soap:address location="http://localhost:80/WeatherServiceApp/WeatherService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
此WSDL不是我自己的,并且取自tutorial。我并不严格遵循本教程,因为Axis使用wsdl2java而不是wsimport进行代码生成,并且我让Eclipse / Axis处理web.xml。
我可以成功生成Web服务,并且使用Eclipse的Web服务的Explorer进行测试可以正常工作。我的问题是,我想使用生成的客户端对此进行测试,而不是仅在本地对Web服务进行测试。我生成了Web服务客户端,并在客户端内部编写了一个非常简单的程序来尝试对其进行测试。
package client;
import java.rmi.RemoteException;
import org.example.www.WeatherService.*;
public class WeatherServiceClient {
public static void main(String [] args) throws RemoteException {
WeatherServiceSOAPStub stub = new WeatherServiceSOAPStub();
GetCurrentTemperatureRq rq = new GetCurrentTemperatureRq();
stub.getCurrentTemperature(rq);
}
}
运行此文件时出现错误。
Nov 19, 2019 11:55:05 AM org.apache.axis.utils.JavaUtils isAttachmentSupported
WARNING: Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
Exception in thread "main" AxisFault
faultCode: {http://xml.apache.org/axis/}Server.NoEndpoint
faultSubcode:
faultString: No endpoint
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}exceptionName:org.apache.axis.NoEndPointException
{http://xml.apache.org/axis/}stackTrace:No endpoint
at org.example.www.WeatherService.WeatherServiceSOAPStub.getCurrentTemperature(WeatherServiceSOAPStub.java:150)
at client.WeatherServiceClient.main(WeatherServiceClient.java:11)
{http://xml.apache.org/axis/}hostname:fake_hostname
No endpoint
at org.example.www.WeatherService.WeatherServiceSOAPStub.getCurrentTemperature(WeatherServiceSOAPStub.java:150)
at client.WeatherServiceClient.main(WeatherServiceClient.java:11)
尝试此操作时,主要的Web服务正在Tomcat中运行。
如何解决此端点问题?我的WSDL中的地址是否有问题,或者是否需要更改soapAction?
我的问题似乎与WSDL有关,或者至少与我如何生成客户端有关。我没有先同时生成Web Service和Web Service Client,而是首先生成了Web Service并将其部署到Tomcat。似乎Axis生成了一个略有不同的WSDL,可用于我的目的。