关于用axis2通过java Service 生成Wsdl文件操作

1.首先配置好 axis2 的环境、

2. 直接在CMD中敲入wsdl。可以看到参数提示说明配置成功

----------------------------------------------------------------分割线------------------------------

下面开始生成WSDL 文件

首先路径到java文件的CLASS文件夹目录 ex: C:\Users\D4829\Desktop\TestWebService1\TestWebService1\build\classes

cmd 进入次目录:输入 命令 :java2wsdl -o VLinkPaymentPlanService.wsdl -l "http://localhost:7021/vlink/VLinkPaymentPlanPort" -tn "http://service.velocity.govolution.com/" -p2n ["com.govolution.velocity.service","http://service.velocity.govolution.com/"] -cn com.govolution.velocity.service.VLinkPaymentPlan

就会在Class文件夹下生成一个 WSDL文件夹。

OK WSDL 文件生成成功。

参数具体分析下班以后补上....

转载于:https://www.cnblogs.com/newBegin/p/3456166.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基于 Apache Axis2,我们可以将上述类中的方法对外提供为 web 服务,并生成 WSDL 文件,同时也可以利用 Axis2 客户端代码调用该服务。 首先,我们需要在项目中引入 Axis2 的相关依赖包,并进行配置和部署。 1. 引入依赖包 首先,在项目的 pom.xml 文件中添加相关依赖: ```xml <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2</artifactId> <version>1.7.9</version> </dependency> ``` 2. 配置和部署 在项目的配置文件中,我们需要配置 Axis2 的相关信息,如 web.xml 文件中添加以下内容: ```xml <servlet> <servlet-name>AxisServlet</servlet-name> <display-name>Apache-Axis2</display-name> <servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class> <init-param> <param-name>axis2.repository.path</param-name> <param-value>/WEB-INF/axis2.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>AxisServlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> ``` 在项目的根目录下,创建文件夹 WEB-INF,再在 WEB-INF 目录下创建文件 axis2.xml,文件内容如下: ```xml <axisconfig name="AxisJava2.0"> <handler name="SimpleFileUploadHandler" class="org.apache.axis2.handlers.SimpleFileUploadHandler"/> <deployer extension=".aar" directory="axis2services"/> </axisconfig> ``` 然后,在项目中新建一个类来实现我们的 web 服务: ```java package com.example; public class ExampleService { public String sayHello(String name) { return "Hello, " + name + "!"; } } ``` 在该类中,我们提供了一个名为 sayHello 的方法,用于返回一个字符串。 接下来,我们可以使用 Axis2 的工具类来生成 WSDL 文件,即我们的服务描述文件。 ```java package com.example; import org.apache.axis2.description.AxisService; import org.apache.axis2.description.Parameter; import org.apache.axis2.description.WSDL2Constants; import org.apache.axis2.engine.AxisConfiguration; import org.apache.axis2.transport.http.AxisServlet; import org.apache.axis2.wsdl.WSDLConstants; import org.apache.axis2.wsdl.WSDLUtil; import org.apache.axis2.wsdl.WSDLConstants.WSDL20_2004_Constants; import org.apache.woden.WSDLFactory; import org.apache.woden.WSDLWriter; import javax.servlet.ServletContext; import javax.wsdl.WSDLException; import javax.wsdl.xml.WSDLLocator; import javax.wsdl.xml.WSDLWriter; import java.io.OutputStream; import java.util.Iterator; public class WsdlGenerator { private AxisServlet axisServlet; public WsdlGenerator(AxisServlet axisServlet) { this.axisServlet = axisServlet; } public void generateWsdlFile(OutputStream outputStream, String serviceName) throws WSDLException { AxisConfiguration axisConfiguration = axisServlet.getConfigurationContext().getAxisConfiguration(); AxisService axisService = axisConfiguration.getService(serviceName); WSDLWriter wsdlWriter = WSDLFactory.newInstance().newWSDLWriter(); wsdlWriter.writeWSDL(new WSDL2Constants.WSDL(, new WSDLLocator() { @Override public String getBaseURI() { return null; } @Override public String getLatestImportURI() { return null; } @Override public java.io.Reader getBaseReader() { return null; } @Override public java.io.Reader getImportReader(String parentLocation, String importLocation) { return null; } @Override public javax.wsdl.xml.WSDLLocator getBaseLocator() { return null; } })); The generated WSDL file can then be returned to the caller by writing it to the OutputStream. 提供的参数 outputStream 是用于写入 WSDL 文件的输出流,serviceName 是指定的服务名称。 使用 Axis2 客户端调用我们的服务,可以使用以下代码: ```java package com.example.client; import org.apache.axis2.client.ServiceClient; import org.apache.axis2.transport.http.HTTPConstants; import org.apache.axis2.transport.http.HttpTransportProperties; public class ClientExample { public static void main(String[] args) throws Exception { ServiceClient serviceClient = new ServiceClient(); HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator(); auth.setUsername("username"); auth.setPassword("password"); serviceClient.getOptions().setProperty(HTTPConstants.AUTHENTICATE, auth); serviceClient.getOptions().setTo(targetEPR); serviceClient.sendReceive(operation); } } ``` 在该代码中,我们首先创建一个 ServiceClient 对象,然后设置用户名和密码,接着设置服务的目标地址,最后发送请求。 使用以上步骤,我们可以基于 Apache Axis2 将上述类的方法对外提供为 web 服务,生成 WSDL 文件,并可以使用 Axis2 客户端代码来调用该服务。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值