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