Put the post request on XML files
Function GetSalesForceSessionID() As String Dim SID As String = String.Empty Dim AllowUploadSalesforce As String AllowUploadSalesforce = ConfigurationManager.AppSettings("allowUploadSalesforce").ToLower() If AllowUploadSalesforce = "true" Then '''' Loading XML Data Dim XMLDoc As New StreamReader(Me.Server.MapPath("~") + "/XMLTemplates/WestpacCredentials.xml") '''' Transform XML data to byte array Dim XMLData As String XMLData = XMLDoc.ReadToEnd() Dim PostData As Byte() = Encoding.UTF8.GetBytes(XMLData) '''' Post XML data to Salesforce Dim WClient As New WebClient WClient.Headers.Add("SOAPAction", "login") WClient.Headers.Add("Content-Type", "text/xml; charset=utf-8") Dim OutPutData As Byte() Try OutPutData = WClient.UploadData(ConfigurationManager.AppSettings("SFEndPoint"), "POST", PostData) '''' Reading the the response Dim XMLOutPut As String XMLOutPut = WClient.Encoding.GetString(OutPutData) '''' Transform XML string to XML document Dim XMLOutputDoc As New XmlDocument XMLOutputDoc.LoadXml(XMLOutPut) Dim root As XmlElement root = XMLOutputDoc.DocumentElement '''' Reading SessionID from xml SID = root("soapenv:Body")("loginResponse")("result")("sessionId").InnerText Catch ex As Exception SID = String.Empty Me.SendServiceError(ex.ToString()) End Try WClient.Dispose() End If Return SID End Function
No comments:
Post a Comment