以下是使用 VB.NET 2005 所寫的 Web Sevices範例程式
- 將圖片上傳至Services端
- Service端程式
Imports System.WebImports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.io
Public Function GetPic(ByVal str As String) As Byte()
Dim filename As String = Me.Server.MapPath(".") & "\\" & str & "." & "Jpg"
Dim fs As FileStream = New FileStream(filename, FileMode.Open)
Dim br As BinaryReader = New BinaryReader(fs)
Dim pic As Byte() = br.ReadBytes(fs.Length)
br.Close()
fs.Close()
Return pic
End Function
-Client端程式
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Imaging
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim s As New WebReference2.Service
Dim STR As String = "123"
Dim path As String = Server.MapPath(".")
Dim msImage As MemoryStream = New MemoryStream(s.GetPic("2"))
Dim imgFile As Image = Image.FromStream(msImage)
ImgFile.Save(path + "\" + STR + ".jpg", ImageFormat.Jpeg)
Me.Image1.ImageUrl = "~/" & STR & ".jpg" '在Web上放入一個Image控制項來顯示所取回的圖片
imgFile.Dispose()
End Sub
- 將向服務端請求提供圖片的服務
上面的例子顛倒過來寫就是向服務端請求提供圖片的服務. 有空在繼續放.
要存檔處的資料夾 權限記得要打開給ASP.NET和本機使用儲存.
0 意見:
張貼留言