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

VB调用Jboss Web Service

发布时间:2020-12-16 23:23:50 所属栏目:大数据 来源:网络整理
导读:VB 调用 Jboss Web Service 引言:由于异构系统通信需要,公司需要 pb7 写的系统调用 java 开发的 web 服务,众所周知 pb7 本身没有 web 服务功能,因此, pb7 不能直接调用 java web 服务。为此,不得不使用其它语言( VB 、 donet 等)封装与 java web 服

VB调用Jboss Web Service

引言:由于异构系统通信需要,公司需要pb7写的系统调用java开发的web服务,众所周知pb7本身没有web服务功能,因此,pb7不能直接调用java web服务。为此,不得不使用其它语言(VBdonet等)封装与java web服务进行通讯的dllpb去调用,间接的实现pb调用java web服务。Pb调用dll或者com组件网上比较多,在本人另外一篇博文PB7调用C# dll中也有详细的说明,因此本文着重讲述了vb如何调用Jboss Web Service。选用VB还不是C#是因为,很多客户端是pos机,配置较低。

一、 JWS(Jboss Web Service)的创建

我们将创建一个基于JSR-181 规范的Web Service 及其对应的客户端。开发一个JSR-181 POJO EndpointWeb Service 应遵守下面几个步骤:建立一个POJO endpointendpoint 定义成一个servletendpoint 打包成一个Web 应用(war 文件)

1) 建立一个POJO endpoint

/**

* @author bighorse

*/

package com.jbossws.server;

import javax.jws.WebMethod;

import javax.jws.WebParam;

import javax.jws.WebService;

import javax.jws.soap.SOAPBinding;

@WebService(name = "HelloWorld",targetNamespace="http://com.jbossws.server/helloworld")

@SOAPBinding(style = SOAPBinding.Style.RPC,parameterStyle = SOAPBinding.ParameterStyle.BARE)

public class HelloWorldWS implements HelloWorldInterface

{

@WebMethod(operationName = "sayHello",exclude = false)

public String sayHello(@WebParam(targetNamespace="http://com.jbossws.server/helloworld",

partName = "msg",name = "msg")String msg)

{

System.out.println("I'm Hit! " + msg);

return "Hello World: " + msg + " on " + new java.util.Date();

}

@WebMethod

public String sayWorld() {

// TODO Auto-generated method stub

return "sayWorld with no args";

}

}

package com.jbossws.server;

import java.rmi.Remote;

public interface HelloWorldInterface extends Remote{

public String sayHello(String msg);

public String sayWorld();

}

2) endpoint 定义成一个servletWEB-INF/web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation = "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"

version="2.4">

<servlet>

<servlet-name>HelloWorldService</servlet-name>

<servlet-class>com.jbossws.server.HelloWorldWS</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>HelloWorldService</servlet-name>

<url-pattern>/HelloWorldService</url-pattern>

</servlet-mapping>

</web-app>

3) endpoint 打包成一个Web 应用(war 文件),下面是Ant配置文件build.xml的片段

<target name="war" depends="compile" description="创建WS 发布包">

<war warfile="${app.dir}/helloworldws.war" webxml="${app.dir}/WEB-INF/web.xml">

<classes dir="${build.classes.dir}">

</classes>

</war>

</target>

经过上面的步骤,完成了一个Web Service 的开发,下面我们通过Jboss 管理平台查看刚才发布的Web Service ,我们可以输入http://localhost:8000/jbossws/进入JbossWS 的查看界面。

二、 VB使用SOAP消息调用JWS

1) SOAP简介

a. SOAP定义

SOAPSimple Object Access Protocol )简单对象访问协议是在分散或分布式的环境中交换信息的简单的协议,是一个基于XML的协议,它包括四个部分:

·SOAP封装(envelop):封装定义了一个描述消息中的内容是什么,是谁发送的,谁应当接受并处理它以及如何处理它们的框架;

·SOAP编码规则(encoding rules):用于表示应用程序需要使用的数据类型的实例;

·SOAP RPC表示(RPC representation):表示远程过程调用和应答的协定;

·SOAP绑定(binding):使用底层协议交换信息。

b. SOAP消息

SOAP采用了已经广泛使用的两个协议:HTTPXML。其中HTTP用于实现SOAPRPC风格的传输,而XML是它的编码模式,一个SOAP请求实际上就是一个HTTP POST请求。

2) WSDL简介

WSDL (Web Services Description Language)是一种XML Application,他的作用是将一个Web Services描述为一组服务访问点。WSDL文档将一个Web Services描述成一组网络端点或者端口,WSDL,由于服务访问点和消息的抽象定义已经和具体的服务期部署和数据格式绑定分离,因此可以再次使用这些抽象对象: 消息,是对需要交换信息的抽象描述;端口类型,是对Web Service提供的操作的抽象集合。

特定端口类型的具体协议和数据格式定义构成了一个可以从用的绑定,一个端口定义成一个可重用绑定和网络地址的关联,一组端口构成了一个服务。

WSDL在定义Web Sevices时使用了以下元素:

·Types 数据类型的容器,他采用一些类型系统(比如常用的XSD

·Message 通信消息的抽象类型化定义

·Operation 服务提供的操作的抽象化描述

·Port Type 一个或者多个端点支持的一组操作的抽象

·Binding 特定端口类型的具体协议和数据格式定义

·Port:定义为binding和网络地址的关联的单个的端点

·Service 一组相关的端点的结合

3) VB编写客户端程序

a. 环境准备

要使用SOAP消息访问Web Service消息。必须先下载MicroSoft公司提供的Soap ToolKithttp://download.microsoft.com/download/xml/soap/2.0/W98NT42KMe/EN-US/SoapToolkit20.exe

b. 编写VB客户端应用

c. 编写SOAP消息

<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><env:Header/>"

<env:Body>

<ns1:sayHello xmlns:ns1='http://com.jbossws.server/helloworld'>

<msg>佛山人</msg>

</ns1:sayHello>

</env:Body>

</env:Envelope>

d. 显示处理结果

<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>

<env:Header></env:Header>

<env:Body><ns1:sayHelloResponse xmlns:ns1='http://com.jbossws.server/helloworld'>

<return>Hello World: 佛山人 on Sun Jul 01 16:14:42 CST 2007</return>

</ns1:sayHelloResponse>

</env:Body>

</env:Envelope>

我们需要使用ToolKit中的xml解析器对他进行解析才能获取我们需要的结果。

e. VB客户端代码

Private Sub CommandButton1_Click()

Dim xmlhttp As New MSXML2.xmlhttp

Dim soaprequest As String

Dim postUrl As String

Dim strout As String

Dim xmldoc As New MSXML2.DOMDocument

postUrl = "http://127.0.0.1:8000/helloworldws/HelloWorldService"

xmlhttp.Open "POST",postUrl,False

soaprequest = "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>"

soaprequest = soaprequest & " <env:Header/>"

soaprequest = soaprequest & " <env:Body>"

soaprequest = soaprequest & " <ns1:sayHello xmlns:ns1='http://com.jbossws.server/helloworld'>"

soaprequest = soaprequest & " <msg>佛山人</msg>"

soaprequest = soaprequest & " </ns1:sayHello>"

soaprequest = soaprequest & " </env:Body>"

soaprequest = soaprequest & " </env:Envelope>"

xmlhttp.setRequestHeader "Content-Length",Len(soaprequest)

xmlhttp.setRequestHeader "SOAPAction",""

xmlhttp.send (soaprequest)

strout = xmlhttp.responseText

xmldoc.loadXML strout

'MsgBox strout.Item(0).Text

MsgBox xmldoc.getElementsByTagName("return").Item(0).Text

End Sub

(编辑:李大同)

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

    推荐文章
      热点阅读