Web Services 线程“main”org.apache.axis2.AxisFault出现异常:请实现jdl.helloworld.webservices.服务,你好世界 backbone #说你好

guykilcj  于 2022-11-15  发布在  Apache
关注(0)|答案(1)|浏览(150)

我是Web服务新手。我正在尝试通过Axis2引擎实现一个示例WSDL Web服务。

Versions: Axis2 - > axis2-1.1.1, Ant - > apache-ant-1.8.2

创建Web服务时没有任何错误。当我通过命令提示符(Ant测试)进行测试时,我收到如下错误

[java] Exception in thread "main" org.apache.axis2.AxisFault: Please implem
ent jdl.helloworld.webservices.service.HelloWorldSkeleton#SayHello
     [java]     at org.apache.axis2.description.OutInAxisOperationClient.send(Ou
tInAxisOperation.java:271)
     [java]     at org.apache.axis2.description.OutInAxisOperationClient.execute
(OutInAxisOperation.java:202)
     [java]     at jdl.helloworld.webservices.service.HelloWorldStub.SayHello(Un
known Source)
     [java]     at jdl.helloworld.webservices.client.Client.main(Unknown Source)

     [java] Java Result: 1

这是HelloWorldServiceSkeleton.javajdl\helloworld\webservices\服务目录下的www.example.com

package jdl.helloworld.webservices.service;

import org.apache.ws.axis2.helloworld.SayHello;
import org.apache.ws.axis2.helloworld.SayHelloResponse;
import org.apache.ws.axis2.helloworld.PrintValues;

public class HelloWorldServiceSkeleton 
{
    public org.apache.ws.axis2.helloworld.SayHelloResponse SayHello(org.apache.ws.axis2.helloworld.SayHello param0)throws Exception {
        SayHelloResponse sayHelloResponse=new SayHelloResponse();
        try{

            sayHelloResponse.setName(param0.getName());
            System.out.println("Hello World Service called");
        }catch(Exception e){
            System.out.println(" Error Occured : "+e);
        }
        return sayHelloResponse;
    }

    public String PrintValues(org.apache.ws.axis2.helloworld.PrintValues param1){
        return "printvalues";
    }

}

Client.java 文件

package jdl.helloworld.webservices.client;

import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import jdl.helloworld.webservices.service.HelloWorldStub;
import jdl.helloworld.webservices.service.HelloWorldStub.SayHello;
import jdl.helloworld.webservices.service.HelloWorldStub.SayHelloResponse;
import jdl.helloworld.webservices.service.HelloWorldStub.PrintValues;
import jdl.helloworld.webservices.service.HelloWorldStub.PrintValuesResponse;

public class Client 
{
    public static void main(String[] args)throws Exception 
    {               
        System.out.println("-- Inside Client --");
        ConfigurationContext configurationContext=ConfigurationContextFactory.createConfigurationContextFromFileSystem("C:\\axis2-1.1.1\\repository", "C:\\axis2-1.1.1\\conf\\axis2.xml");
        HelloWorldStub helloWorldStub=new HelloWorldStub(configurationContext,"http://localhost:8080/axis2/services/HelloWorld");
        System.out.println(" --> sayHello Begin");
        SayHello sayHello=new SayHello();
        sayHello.setName("user");       
        SayHelloResponse sayHelloResponse=helloWorldStub.SayHello(sayHello);            
        System.out.println(" --> sayHello Response : "+sayHelloResponse.getName());         
    }
}

HelloWorld.wsdl文件

<wsdl:definitions name="HelloWorld"
    xmlns:tns="http://ws.apache.org/axis2/HelloWorld/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    targetNamespace="http://ws.apache.org/axis2/HelloWorld/">
    <wsdl:types>
        <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            elementFormDefault="qualified"
            targetNamespace="http://ws.apache.org/axis2/HelloWorld/">
            <xsd:element name="SayHello">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element minOccurs="0" name="Name" type="xsd:string"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>       
            <xsd:element name="SayHelloResponse">
                <xsd:complexType>        
                    <xsd:sequence>
                        <xsd:element name="Name" minOccurs="0" type="xsd:string"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="PrintValues">
                <xsd:complexType>        
                    <xsd:sequence>
                        <xsd:element name="Name" minOccurs="0" type="xsd:string"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="PrintValuesResponse">
                <xsd:complexType>        
                    <xsd:sequence>
                        <xsd:element name="Name" minOccurs="0" type="xsd:string"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
        </xsd:schema>
    </wsdl:types>
    <wsdl:message name="SayHelloSoapIn">
        <wsdl:part name="parameters" element="tns:SayHello"/>
    </wsdl:message>  
    <wsdl:message name="SayHelloSoapOut">
        <wsdl:part name="parameters" element="tns:SayHelloResponse"/>
    </wsdl:message>

    <wsdl:message name="PrintValuesSoapOut">
        <wsdl:part name="parameters" element="tns:PrintValues"/>
    </wsdl:message>
    <wsdl:message name="PrintValuesSoapOut">
        <wsdl:part name="parameters" element="tns:PrintValuesResponse"/>
    </wsdl:message>

    <wsdl:portType name="HelloWorldSoap"> 
        <wsdl:operation name="SayHello">
            <wsdl:input message="tns:SayHelloSoapIn"/>
            <wsdl:output message="tns:SayHelloSoapOut"/>
        </wsdl:operation>
        <wsdl:operation name="PrintValues">
            <wsdl:input message="tns:PrintValuesSoapIn"/>
            <wsdl:output message="tns:PrintValuesSoapOut"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="HelloWorldSoap" type="tns:HelloWorldSoap">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <wsdl:operation name="SayHello">
            <soap:operation soapAction="http://localhost:8080/axis2/HelloWorld/SayHello" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>        
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>

        <wsdl:operation name="PrintValues">
            <soap:operation soapAction="http://localhost:8080/axis2/HelloWorld/PrintValues" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>        
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="HelloWorld">
        <wsdl:port name="HelloWorldSoap"
            binding="tns:HelloWorldSoap">
            <soap:address location="http://localhost:8080/axis2/services/HelloWorld" />
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

请帮帮我

dldeef67

dldeef671#

您是否使用wsdl2java从WSDL生成Java类?wsdl2java会为您生成一个框架服务类,并生成一个services.xml文件,该文件指示使用框架类作为服务类。自动生成的框架会针对它处理的任何Web服务调用抛出一个AxisFault消息。看起来Axis2正在使用此框架类作为服务类。而不是服务类。
通常,您将编写一个扩展 backbone 类(或者实现 backbone 接口)的服务类。在打包服务时,您应该更改services.xml文件,以便它将您的类指定为服务类,而不是自动生成的 backbone 类。

相关问题