我正在尝试从应用程序本身上传文件到WCF服务。我的WCF服务是这样的:
<WebInvoke(UriTemplate:="uploadimage?name={name}", Method:="Post")>
Function UploadImage(ByVal stream As Stream, ByVal name As String) As String
我试图在按钮点击的同一项目中调用它,如下所示:
Protected Sub btntest_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btntest.Click
I am using IIS hosting within same project.
Dim req As HttpWebRequest = DirectCast(HttpWebRequest.Create("http://localhost:29723/HighriseeSite/appservices.svc" & "/uploadimage?name="), HttpWebRequest)
req.Method = "POST"
req.ContentType = "text/plain"
Dim reqStream As Stream = req.GetRequestStream()
Dim fileToSend As Byte() = New Byte(12344) {}
For i As Integer = 0 To fileToSend.Length - 1
fileToSend(i) = CByte("a"c & (i Mod 26))
Next
reqStream.Write(fileToSend, 0, fileToSend.Length)
reqStream.Close()
Dim resp As HttpWebResponse = DirectCast(req.GetResponse(), HttpWebResponse)
Console.WriteLine("HTTP/{0} {1} {2}", resp.ProtocolVersion, CInt(resp.StatusCode), resp.StatusDescription)