[英]How to consume a top-down web service?
I've been having various issues with a rather complex web service that I've been trying to implement with Eclipse, Tomcat 8, and Axis.我一直在尝试使用 Eclipse、Tomcat 8 和 Axis 实现的相当复杂的 web 服务遇到各种问题。 This is my first experience with web services so I decided to start messing around with something more simple to make sure that I know what I'm doing.
这是我第一次使用 web 服务,所以我决定开始尝试一些更简单的东西,以确保我知道自己在做什么。 This is the WSDL that I'm currently using to generate a service from in Eclipse.
这是我目前用来从 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>
This WSDL is not my own and was taken from a tutorial .这个 WSDL 不是我自己的,取自 教程。 I am not strictly following this tutorial as Axis is using wsdl2java for code generation instead of wsimport and I let Eclipse/Axis take care of the web.xml.
我没有严格遵循本教程,因为 Axis 使用 wsdl2java 而不是 wsimport 进行代码生成,我让 Eclipse/Axis 处理 web.xml。
I can successfully generate the Web Service and testing using Eclipse's Web Service's Explorer works correctly.我可以成功生成 Web 服务并使用 Eclipse 的 Web 服务的资源管理器进行测试工作正常。 My issue is that I want to test this using a generated client instead of just doing it locally to the web service.
我的问题是我想使用生成的客户端进行测试,而不是仅在本地对 web 服务进行测试。 I generated the web service client and wrote a very simple program inside the client to try and test it.
我生成了 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);
}
}
Upon running this I get an error.运行这个我得到一个错误。
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)
The main web service is running in Tomcat when I try this.当我尝试这个时,主要的 web 服务正在 Tomcat 中运行。
How do I fix this Endpoint issue?如何解决此端点问题? Is there a problem in my WSDL with the address or does soapAction need to be changed?
我的 WSDL 的地址有问题还是需要更改soapAction?
My issue appears to have been with the WSDL or at least how I generated the client.我的问题似乎与 WSDL 或至少我如何生成客户端有关。 Instead of generating the Web Service and the Web Service Client simultaneously, I instead just generated the Web Service first and deployed it to Tomcat.
Instead of generating the Web Service and the Web Service Client simultaneously, I instead just generated the Web Service first and deployed it to Tomcat. It seems that Axis generated a slightly different WSDL that worked for my purpose.
似乎 Axis 生成了一个稍微不同的 WSDL 用于我的目的。
So instead of generating the client based off of the original WSDL, I based it off of the WSDL generated by Axis which was at http://localhost:8080/WeatherService/services/WeatherServiceSOAP?wsdl
in my case. So instead of generating the client based off of the original WSDL, I based it off of the WSDL generated by Axis which was at
http://localhost:8080/WeatherService/services/WeatherServiceSOAP?wsdl
in my case.
For those interested, here is the Axis generated WSDL.对于那些感兴趣的人,这里是 Axis 生成的 WSDL。
<wsdl:definitions xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://www.example.org/WeatherService/" xmlns:intf="http://www.example.org/WeatherService/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/WeatherService/">
<!--
WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)
-->
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/WeatherService/">
<element name="GetCurrentTemperatureRq">
<complexType>
<sequence>
<element name="city" type="xsd:string" />
</sequence>
</complexType>
</element>
<element name="GetCurrentTemperatureRs">
<complexType>
<sequence>
<element name="temperature" type="xsd:string" />
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="GetCurrentTemperatureResponse">
<wsdl:part element="impl:GetCurrentTemperatureRs" name="GetCurrentTemperatureRs"></wsdl:part>
</wsdl:message>
<wsdl:message name="GetCurrentTemperatureRequest">
<wsdl:part element="impl:GetCurrentTemperatureRq" name="GetCurrentTemperatureRq"></wsdl:part>
</wsdl:message>
<wsdl:portType name="WeatherServicePortType">
<wsdl:operation name="GetCurrentTemperature" parameterOrder="GetCurrentTemperatureRq">
<wsdl:input message="impl:GetCurrentTemperatureRequest" name="GetCurrentTemperatureRequest"></wsdl:input>
<wsdl:output message="impl:GetCurrentTemperatureResponse" name="GetCurrentTemperatureResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="WeatherServiceSOAPSoapBinding" type="impl:WeatherServicePortType">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="GetCurrentTemperature">
<wsdlsoap:operation soapAction="http://www.example.org/WeatherService/GetCurrentTemperature" />
<wsdl:input name="GetCurrentTemperatureRequest">
<wsdlsoap:body use="literal" />
</wsdl:input>
<wsdl:output name="GetCurrentTemperatureResponse">
<wsdlsoap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="WeatherService">
<wsdl:port binding="impl:WeatherServiceSOAPSoapBinding" name="WeatherServiceSOAP">
<wsdlsoap:address location="http://localhost:8080/WeatherService/services/WeatherServiceSOAP" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.