2014-07-11 66 views
0

我想發送一個包含文件列表的XML文件到一個寧靜的web服務。 它是一個vb.net項目。該數據傳遞到Web服務的功能如下:.net REST風格的Web服務:發送xml文件

Private Function SendActivityToWEBSERVICE(ByVal xmlFile As String) As Boolean 
    Try 
     sUri = "http://localhost:35299/LiveUpdateWS/SincronizzaAttivita?d=" + xmlFile.ToString() 

     Dim req As HttpWebRequest = WebRequest.Create(sUri.ToString()) 
     req.Method = "GET" 
     req.KeepAlive = False 

     Dim response As HttpWebResponse = req.GetResponse() 
     Try 
      Dim xmlDoc As New Xml.XmlDocument 
      xmlDoc.Load(response.GetResponseStream()) 

     Catch exc As XmlException 
      Console.WriteLine("Eccezione " + exc.Message) 
      Return False 
     End Try 

    Catch ex As Exception 
     Console.WriteLine("Eccezione " + ex.Message) 
     Return False 
    End Try 
    Return True 
End Function 

Web服務的界面如下:

<OperationContract> 
<WebGet(UriTemplate:="SincronizzaAttivita?d={sXMLFile}")> 
Function SaveDataPost(sXMLFile As String) As Boolean 

如果我發送XML文件是小尺寸的一切工作正常。 如果我嘗試發送大文件,我得到錯誤404.15。我發現要將字符串或特定大小的數據發送到Web服務,建議使用POST而不是GET。 對我來說目前還不清楚如何修改上面的代碼來做到這一點,總是 ,這是我的問題的解決方案。你能告訴我什麼以及如何更改代碼?

回答

0

你只需要使用POST方法而不是GET req.Method =「POST」

,並在不同的變量,而不是查詢參數發送數據。