线程“main”中的异常org.apache.axis2.AxisFault:请实现jdl.helloworld.webservices.service.HelloWorldSkeleton#SayHello

时间:2011-03-03 10:58:38

标签: web-services axis2

我是网络服务新手。我正在尝试通过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

这是jdl \ helloworld \ webservices \ service目录下的HelloWorldServiceSkeleton.java

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>

请帮帮我。

1 个答案:

答案 0 :(得分:0)

您是否使用wsdl2java从WSDL生成Java类? wsdl2java为您生成一个框架服务类,它生成一个services.xml文件,该文件说使用框架类作为服务类。自动生成的骨架会为其处理的任何Web服务调用抛出带有该消息的AxisFault。似乎Axis2使用此骨架类作为服务类,而不是您的服务类。

通常,您将编写一个扩展框架类的服务类(或者实现框架接口)。打包服务时,应更改services.xml文件,以便将类指定为服务类,而不是自动生成的框架类。