如何使用自上而下的Web服务?

我一直在尝试使用eclipse,Tomcat 8和Axis来实现的一个相当复杂的Web服务遇到各种问题。这是我第一次使用Web服务,因此我决定开始搞一些更简单的事情,以确保我知道自己在做什么。这是我目前用来在eclipse中从中生成服务的WSDL。

_onSelectAllChanged

该WSDL不是我自己的,并且取自tutorial。我并不严格遵循本教程,因为Axis使用wsdl2java而不是wsimport进行代码生成,而我让eclipse / Axis处理web.xml。

我可以成功生成Web服务,并且使用eclipse的Web Service的资源管理器进行测试可以正常工作。我的问题是,我想使用生成的客户端对此进行测试,而不是仅在本地对Web服务进行测试。我生成了Web服务客户端,并在客户端内部编写了一个非常简单的程序来尝试对其进行测试。

<?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>

运行此命令时出现错误。

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);
    }
}

尝试此操作时,主要的Web服务正在Tomcat中运行。

如何解决此端点问题?我的WSDL中的地址是否有问题,或者是否需要更改soapaction?

jackchesun 回答:如何使用自上而下的Web服务?

我的问题似乎与WSDL有关,或者至少与我如何生成客户端有关。我没有先同时生成Web Service和Web Service Client,而是首先生成了Web Service并将其部署到Tomcat。似乎Axis生成了一个略有不同的WSDL,可以达到我的目的。

因此,我不是基于原始WSDL生成客户端,而是基于Axis生成的WSDL(在我的案例中为http://localhost:8080/WeatherService/services/WeatherServiceSOAP?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>
本文链接:https://www.f2er.com/3071559.html

大家都在问