0

我需要从另一家公司的 WSDL 文件创建一个 Web 服务(服务器应用程序,而不是客户端)。我已经从 WSDL 创建了客户端应用程序,但从未创建过服务器应用程序。没有其他公司提供的文件,但我在网上找到了这个(第 64 页);它是从 2008 年开始的,但他们告诉我信息仍然有效(尽管链接无效)。我从这个zip 文件中得到了 Notification.wsdl 和 Notification.XSD 。

我在这个命令行中使用了 WSDL2Java:

java org.apache.axis.wsdl.WSDL2Java --server-side Notification.wsdl

并创建了几个 java 源文件和 deploy/undeploy.wsdd 文件。但是 deploy.wsdd 看起来不像我预期的那样基于 Axis 文档。它只包含:

<deployment
    xmlns="http://xml.apache.org/axis/wsdd/"
    xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
</deployment>

至少不应该有一个<service>条目,还是我需要手动创建?我希望它是自动创建的。WSDL 文件中是否缺少某些内容?还是我在某个地方错过了一步?

戴夫

4

1 回答 1

1

If you are using Axis 1.4 command WSDL2Java does not create you a proper .wsdd file. You always need to edit it.

I am using ANT to generated axis server side classes:

   <target name="build-server-jar">
        <mkdir dir="${build}/libs_gen"/>
        <axis-generate serverside="true"
                       srcDir="${ant.dirs.wsdl}"
                       destDir="${build.ws.dir}/${project.name}-server"
                       wsdl="${project.wsdl}"
                       nspkg="${project.nspkg}"/>
        <javac srcdir="${build.ws.dir}/${project.name}-server"
               destdir="${build.ws.dir}/${project.name}-server"
               classpathref="classpath.build"
               includeantruntime="no"/>
        <jar destfile="${build}/libs_gen/my-axis-ws.jar"
             basedir="${build.ws.dir}/${project.name}-server"
             includes="**/*.class"/>
        <copy todir="${lib}" overwrite="true">
            <fileset dir="${build}/libs_gen" includes="my-axis-ws.jar"/>
        </copy>
    </target>

The generated deploy.wsdd file looks like this:

<deployment
    xmlns="http://xml.apache.org/axis/wsdd/"
    xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

  <service name="MyAxis" provider="java:RPC" style="wrapped" use="literal">
      <parameter name="wsdlTargetNamespace" value="http://example.com/ws/myaxis"/>
      <parameter name="wsdlServiceElement" value="MyAxis"/>
      <parameter name="schemaUnqualified" value="http://example.com/ws/myaxis/types"/>
      <parameter name="wsdlServicePort" value="MyAxis"/>
      <parameter name="className" value="com.example.ws.myaxis.MyAxisPortBindingImpl"/>
      <parameter name="wsdlPortType" value="MyAxisService"/>
      <parameter name="typeMappingVersion" value="1.2"/>

      //Generated operations

      //Generated type mappings.

  </service>
</deployment>

Then I have to edit it to look like this:

<deployment
        xmlns="http://xml.apache.org/axis/wsdd/"
        xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

    <globalConfiguration>
        <parameter name="disablePrettyXML" value="false"/>
        <parameter name="sendXsiTypes" value="true"/>
        <parameter name="sendMultiRefs" value="true"/>
        <parameter name="sendXMLDeclaration" value="true"/>
    </globalConfiguration>

    <handler name="LocalResponder" type="java:org.apache.axis.transport.local.LocalResponder"/>
    <handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper"/>
    <handler name="Authenticate" type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"/>

    <service name="MyAxis" provider="java:SPRING" style="wrapped" use="literal">
        <parameter name="springBeanId" value="mySpringBean"/>
        <parameter name="wsdlTargetNamespace" value="http://example.com/ws/myaxis"/>
        <parameter name="wsdlServiceElement" value="MyAxis"/>
        <parameter name="schemaUnqualified" value="http://example.com/ws/myaxis/types"/>
        <parameter name="wsdlServicePort" value="MyAxis"/>
        <parameter name="className" value="com.example.ws.myaxis.MyAxisImpl"/>
        <parameter name="wsdlPortType" value="MyAxisService"/>
        <parameter name="typeMappingVersion" value="1.2"/>

        //Generated operations

        //Generated type mappings

        <wsdlFile>WEB-INF/wsdl/MyAxis.wsdl</wsdlFile>
    </service>

    <transport name="http">
        <requestFlow>
            <handler type="URLMapper"/>
            <handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/>
        </requestFlow>
    </transport>

</deployment>

Why your WSDL2Java command does not generate service, operations and type mappings my guess is it depends on version you are using.

I am using axis-1.4 and axis-ant-1.4. It generates me everything, but I still need to make some changes. So I suggest you try ANT and use those version and at least service, operations and type mappings will be generated.

于 2012-06-10T17:44:23.173 回答