2014-07-11 73 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”

,并在不同的变量,而不是查询参数发送数据。