加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

webServices 服务的搭建

发布时间:2020-12-16 23:24:39 所属栏目:安全 来源:网络整理
导读:webServices? 服务的搭建 首先建立一个 web 工程, web.xml 中加入 ???? servlet ??????? servlet-name AxisServlet / servlet-name ??????? servlet-class org.apache.axis.transport.http.AxisServlet / servlet-class ???? / servlet ???? servlet-mappin

webServices?服务的搭建

首先建立一个web工程,web.xml中加入

????<servlet>

???????<servlet-name>AxisServlet</servlet-name>

???????<servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>

????</servlet>

????<servlet-mapping>

???????<url-pattern>/servlet/AxisServlet/*</url-pattern>

????</servlet-mapping>

????<url-pattern>*.jws</url-pattern>/services/*</servlet-mapping>

然后新建一个server-config.wsdd文件添加以下内容

<deployment?xmlns="http://xml.apache.org/axis/wsdd/"

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

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

?

????<!--?自定义服务?-->

????<service?"HelloTest"?provider="java:RPC"?style="wrapped"?use="literal">

???????<parameter?"className"?value="com.ustcinfo.test.Hello"?/>

???????<"allowedMethods"?"sayHello"?/>

????</service>

????<"InterFaceTest"?"cn.com.starit.iaos.interfa.broadbrand.BroadBrandAlterBack"?/>

???????<"getMsgFault"?/>

????</transport?"http">

???????<requestFlow>

???????????<"URLMapper"?/>

???????</requestFlow>

????</transport>

</deployment>

然后再新建一个java文件


public class Hello {
    public String sayHello(String name,int age){
       System.out.println("hello zusheng");
       return "hello,"+name+"!your age is"+age;
    }
 
}

这样在地址输入:

http://127.0.0.1:8080/iaos-web/services/Hello?wsdl就可以正常访问webservices服务了。

Webservices ?服务端调用

 package com.ustcinfo.test;
import static org.junit.Assert.*;
import java.net.URL;
import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.junit.Before;
import org.junit.Test;
public class Test1 {
private String xml[] = {new String("<?xml version="1.0" encoding="UTF-8"?><request><callNum>152560w00865</callNum><changeTime>2014-04-01 22:35:53<changeTime><broadbandAccount>212223131243213</broadbandAccount><cityid>551</cityid><digitCode>1231<diitCode><acceptCode>05516552312</acceptCode><productID>123456</productID><flag>10000</flag></request>")};
private String wServiceUrl = "http://192.168.217.25:8080/iaos-web/services/InterFaceTest";
private String wsdlUrl = wServiceUrl+"?wsdl";
private final void test() throws Exception{
Service s = new Service();
Call call = (Call)s.createCall();
 call.setOperationName(new QName(wServiceUrl,"getMsgFault"));
 call.setTargetEndpointAddress(new URL(wsdlUrl));  
 String version = (String) call.invoke(xml);  
 System.err.println(version);  
 assertNotNull(version);
}
public static void main(String[] args) throws Exception
{
Test1 t1= new Test1();
t1.test();
}
} 

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读