2
我想弄清楚如何使用servicestack將文件發佈到我的webservice。我有下面的代碼在我的客戶如何使用Servicestack PostFileWithRequest
Dim client As JsonServiceClient = New JsonServiceClient(api)
Dim rootpath As String = Server.MapPath(("~/" + "temp"))
Dim filename As String = (Guid.NewGuid.ToString.Substring(0, 7) + FileUpload1.FileName)
rootpath = (rootpath + ("/" + filename))
FileUpload1.SaveAs(rootpath)
Dim fileToUpload = New FileInfo(rootpath)
Dim document As AddIDVerification = New AddIDVerification
document.CountryOfIssue = ddlCountry.SelectedValue
document.ExpiryDate = DocumentExipiry.SelectedDate
document.VerificationMethod = ddlVerificationMethod.SelectedValue
Dim responseD As MTM.DTO.AddIDVerificationResponse = client.PostFileWithRequest(Of DTO.AddIDVerificationResponse)("http://localhost:50044/images/", fileToUpload, document)
但無論我做什麼,我得到錯誤信息「不允許的方法」。目前的服務器代碼是這樣寫的
Public Class AddIDVerificationService
Implements IService(Of DTO.AddIDVerification)
Public Function Execute(orequest As DTO.AddIDVerification) As Object Implements ServiceStack.ServiceHost.IService(Of DTO.AddIDVerification).Execute
Return New DTO.AddIDVerificationResponse With {.Result = "success"}
End Function
End Class
正如你所看到的,我還沒有嘗試過處理服務器上的文件。我只是想測試客戶端,以確保它實際上可以將文件發送到服務器。任何想法我做錯了什麼?
我確實打算在移動到新的風格的API,但現在我需要一個快速的解決這個問題。例如,該示例沒有告訴我如何使用PostFileWithRequest或者爲什麼我得到「現在允許的方法」。我的代碼中使用舊式API有什麼問題嗎? –
如果您得到405的方法不允許,您可能需要[刪除WebDav](http://stackoverflow.com/a/10283694/85785) – mythz
這對我不起作用。按照指示添加了,但仍然不允許使用該方法。任何人有任何想法? –