VB.NET客户端调用Axis的Java Web Service实现文件上传

1. Java Web Service类DocumentFileManagement:

import java.io.*;
/**
* @author tyrone
*
*/

public class DocumentFileManagement {

//文件名, 文件内容,保存到d盘根目录
public String saveFile(String filename,byte[] contents){
if (filename==null || contents==null)
return "null";
String filepath="d:\\";
File fp=new File(filepath+filename);
try{
BufferedOutputStream op=new BufferedOutputStream(new FileOutputStream(fp));
op.write(contents,0,contents.length);
op.flush();
op.close();
if(fp.exists())
return fp.getAbsolutePath();
else
return "failure to create";
}catch(java.io.IOException e){
return e.getMessage();
}
}
}

2 部署到Axis服务器:

生成depoy.wsdd

<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name="DocumentFileManagement" provider="java:RPC">
<parameter name="className" value="DocumentFileManagement"/>
<parameter name="allowedMethods" value="saveFile"/>
</service>
</deployment>

命令行:/>AdminClient depoy.wsdd

3. copy DocumentFileManagement .class 到 axis\WEB-INF\classes目录

4. 用.NET的wsdl.exe生成VB.NET客户端类

命令行:/>wsdl /language:vb http://localhost:8080/axis/services/DocumentFileManagement?wsdl

生成DocumentFileManagementService.vb

'------------------------------------------------------------------------------
' <autogenerated>
' This code was generated by a tool.
' Runtime Version: 1.1.4322.573
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </autogenerated>
'------------------------------------------------------------------------------

Option Strict Off
Option Explicit On

Imports System
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml.Serialization

'
'This source code was auto-generated by wsdl, Version=1.1.4322.573.
'

'<remarks/>
<System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute("code"), _
System.Web.Services.WebServiceBindingAttribute(Name:="DocumentFileManagementSoapBinding", [Namespace]:="http://localhost:8080/axis/services/DocumentFileManagement")> _
Public Class DocumentFileManagementService
Inherits System.Web.Services.Protocols.SoapHttpClientProtocol

'<remarks/>
Public Sub New()
MyBase.New
Me.Url = "http://localhost:8080/axis/services/DocumentFileManagement"
End Sub

'<remarks/>
<System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace:="http://DefaultNamespace", ResponseNamespace:="http://localhost:8080/axis/services/DocumentFileManagement")> _
Public Function saveFile(ByVal in0 As String, <System.Xml.Serialization.SoapElementAttribute(DataType:="base64Binary")> ByVal in1() As Byte) As <System.Xml.Serialization.SoapElementAttribute("saveFileReturn")> String
Dim results() As Object = Me.Invoke("saveFile", New Object() {in0, in1})
Return CType(results(0),String)
End Function

'<remarks/>
Public Function BeginsaveFile(ByVal in0 As String, ByVal in1() As Byte, ByVal callback As System.AsyncCallback, ByVal asyncState As Object) As System.IAsyncResult
Return Me.BeginInvoke("saveFile", New Object() {in0, in1}, callback, asyncState)
End Function

'<remarks/>
Public Function EndsaveFile(ByVal asyncResult As System.IAsyncResult) As String
Dim results() As Object = Me.EndInvoke(asyncResult)
Return CType(results(0),String)
End Function
End Class

5. 调用DocumentFileManagementService.vb
Module Module1

Sub Main()
Dim ws As New DocumentFileManagementService
Dim result As String

'connect colimas web service
Dim contents As Byte
Dim fp As System.IO.File
Dim str As System.IO.FileStream
Dim fpname As String

Dim i As Integer

'上传的文件名
fpname = "StevenMills.doc"
str = fp.Open(fpname, 3)
Dim content(str.Length) As Byte
For i = 0 To str.Length - 1
content(i) = str.ReadByte()
Next
Try

'调用WebService的方法
result = ws.saveFile(fpname, content)
Console.Write(result)
Catch ex As Exception
Console.Write(ex.Message())
End Try

End Sub

End Module

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值