laxman Posted June 20, 2008 Posted June 20, 2008 i am developing the Windows application using VB.Net here i need to transfer some information to the my customer server and he will be replying to the information acknowledgement. for this my customer given a url and asked me to invoke the url and add the information as a string. here i dont know how to invoke this url and add string so please guide me what i should do and my customer said he will be acknowledged me with the out put i also dont know how to capture the acknowledgement i can give the url ends with ip/web/servlet so please tell me how can i do this Quote
Administrators PlausiblyDamp Posted June 20, 2008 Administrators Posted June 20, 2008 Without knowing exactly what format the request and response take it is a bit difficult to give any exact advice. Could you show the url format / response format? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Nate Bross Posted June 20, 2008 Posted June 20, 2008 Try something like this Imports System Imports System.IO Imports System.Net Module Module1 Sub Main() 'Address of URL Dim URL As String = "http://customer.com/customerURL.ext?query=String" ' Get HTML data Dim client As WebClient = New WebClient() Dim data As Stream = client.OpenRead(URL) Dim reader As StreamReader = New StreamReader(data) Dim str As String = "" str = reader.ReadLine() Do While str.Length > 0 Console.WriteLine(str) str = reader.ReadLine() Loop End Sub End Module Also, try this link where the above sample came from. There are additional samples available here. I cannot tell from your description; however, if your customer is trying to have you use a webservice they have, all you need to do is add the URL they provide as a "Web Reference" to your application. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
laxman Posted June 21, 2008 Author Posted June 21, 2008 Request and Responce will be in XML formate here i am sending the details it is a private ip http://156.0.11.27/webmethod/servelet and i need to add XML file for the above url in this formate <Request> <Transaction ID>101</Transaction ID> <User Name>LAX</User Name> </request> They will acknowledge me by this XML formate <Acknowledge> <Transaction ID>101</Transaction ID> <Status>0</Status> </Acknowledge> Thank You for the reply Quote
Administrators PlausiblyDamp Posted June 21, 2008 Administrators Posted June 21, 2008 Is the other system a web service? If so you can add a web reference to it from the solution explorer in visual studio - that will take care of the hard work. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Nate Bross Posted June 23, 2008 Posted June 23, 2008 If it's not a "web service" this may be useful: http://www.hanselman.com/blog/HTTPPOSTsAndHTTPGETsWithWebClientAndCAndFakingAPostBack.aspx Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
laxman Posted June 24, 2008 Author Posted June 24, 2008 (edited) i tried with the code i am getting an error The Remote Server returned an error (404) Not Found can any one tell what may be went wrong my code is Dim request As WebRequest = WebRequest.Create("http://156.0.11.27:9080/Update/UpdateServlet?<RequestXml><MachineIp>10.0.0.1</MachineIp><TransactionId>110</ TransactionId ><RequestTime>24/06/2008 12:02:40 PM</RequestTime>(MM/DD/YYYY H:MI:SS)</RequestXml>") request.Method = "POST" Dim postData As String = "This is a test that posts this string to a Web server." Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData) Dim instance As New WebException Dim value As WebExceptionStatus request.ContentType = "application/x-www-form-urlencoded" request.ContentLength = byteArray.Length Dim dataStream As Stream = request.GetRequestStream() dataStream.Write(byteArray, 0, byteArray.Length) ' Close the Stream object. dataStream.Close() ' Get the response. value = instance.Status Dim response As WebResponse = request.GetResponse() ' Display the status. Console.WriteLine(CType(response, HttpWebResponse).StatusDescription) ' Get the stream containing content returned by the server. dataStream = response.GetResponseStream() Edited June 24, 2008 by PlausiblyDamp Quote
Administrators PlausiblyDamp Posted June 24, 2008 Administrators Posted June 24, 2008 If you browse direct to http://156.0.11.27/webmethod/servelet what happens? A 404 result would indicate that the URL itself doesn't exist / is misspelled rather than any problem with the code itself. Is the remote site expecting the xml to be appended to the url or sent as a POST or even a SOAP request? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Nate Bross Posted June 24, 2008 Posted June 24, 2008 As PD pointed out, 404 indicates that the URL itself is incorrect. If the URL is correct, and the page expect the data as a "POST" try these modifications: Dim request As WebRequest = _ WebRequest.Create("http://156.0.11.27:9080/Update/UpdateServlet/") request.Method = "POST" Dim postData As String = "<RequestXml><MachineIp>10.0.0.1</MachineIp><TransactionId>110</ TransactionId ><RequestTime>24/06/2008 12:02:40 PM</RequestTime>(MM/DD/YYYY H:MI:SS)</RequestXml>" Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData) Dim instance As New WebException Dim value As WebExceptionStatus request.ContentType = "application/x-www-form-urlencoded" request.ContentLength = byteArray.Length Dim dataStream As Stream = request.GetRequestStream() dataStream.Write(byteArray, 0, byteArray.Length) ' Close the Stream object. dataStream.Close() ' Get the response. value = instance.Status Dim response As WebResponse = request.GetResponse() ' Display the status. Console.WriteLine(CType(response, HttpWebResponse).StatusDescription) ' Get the stream containing content returned by the server. dataStream = response.GetResponseStream() Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
laxman Posted June 25, 2008 Author Posted June 25, 2008 Hai Thank You The service expecting the XML as post method and i tried with the coding It is working fine thank you for every one Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.