By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,977 Members | 1,137 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,977 IT Pros & Developers. It's quick & easy.

consume web service via httpwebrequest

P: n/a
hello all,

trying to consume a simple web service using httpwebrequest instead of
generating a proxy class.

code for simple web service:

Imports System.Web.Services

<System.Web.Services.WebService(Namespace :=
"http://tempuri.org/SoapServer/Service1")_
Public Class Service1
Inherits System.Web.Services.WebService

<WebMethod()_
Public Function HelloWorld() As String
Return "Hello World"
End Function
End Class

code to consume web service using httpwebrequest object:

Dim sTmp As String
sTmp = "" & _
"<?xml version=" + Chr(34) + "1.0" + Chr(34) + " encoding="
+ Chr(34) + "utf-8" + Chr(34) + "?>" & _
"<soap:Envelope xmlns:xsi=" + Chr(34) +
"http://www.w3.org/2001/XMLSchema-instance" + Chr(34) + " xmlns:xsd=" +
Chr(34) + "http://www.w3.org/2001/XMLSchema" + Chr(34) + " xmlns:soap="
+ Chr(34) + "http://schemas.xmlsoap.org/soap/envelope/" + Chr(34) + ">"
& _
"<soap:Body>" & _
"<HelloWorld xmlns=" + Chr(34) +
"http://tempuri.org/SoapServer/Service1" + Chr(34) + " />" & _
"</soap:Body>" & _
"</soap:Envelope>"

objHttpRequest =
WebRequest.Create("http://localhost/SoapServer/Service1.asmx")
objHttpRequest.Method = "POST"
objHttpRequest.ContentType = "text/xml"
objHttpRequest.ContentLength = sTmp.Length
objHttpRequest.Headers.Add("SOAPAction",
"http://tempuri.org/SoapServer/Service1/HelloWorld")

myWriter = New StreamWriter(objHttpRequest.GetRequestStream())
myWriter.Write(sTmp)

objHttpResponse = objHttpRequest.GetResponse
objResponseStream = New
StreamReader(objHttpResponse.GetResponseStream())
sResult = objResponseStream.ReadToEnd
objResponseStream.Close()

================================================== ===============
================================================== ===============

the code fails at objHttpResponse = objHttpRequest.GetResponse, an
exception is thrown stating the request timed out.

pointers appreciated..

thanks in advance

Jul 13 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Make sure to use as namespace your domain and make
sure the server, where the service is hosted, is up and running (try
to load directly the asmx to see if it works) ...

-t

hharry ha scritto:
hello all,

trying to consume a simple web service using httpwebrequest instead of
generating a proxy class.

code for simple web service:

Imports System.Web.Services

<System.Web.Services.WebService(Namespace :=
"http://tempuri.org/SoapServer/Service1")_
Public Class Service1
Inherits System.Web.Services.WebService

<WebMethod()_
Public Function HelloWorld() As String
Return "Hello World"
End Function
End Class

code to consume web service using httpwebrequest object:

Dim sTmp As String
sTmp = "" & _
"<?xml version=" + Chr(34) + "1.0" + Chr(34) + " encoding="
+ Chr(34) + "utf-8" + Chr(34) + "?>" & _
"<soap:Envelope xmlns:xsi=" + Chr(34) +
"http://www.w3.org/2001/XMLSchema-instance" + Chr(34) + " xmlns:xsd=" +
Chr(34) + "http://www.w3.org/2001/XMLSchema" + Chr(34) + " xmlns:soap="
+ Chr(34) + "http://schemas.xmlsoap.org/soap/envelope/" + Chr(34) + ">"
& _
"<soap:Body>" & _
"<HelloWorld xmlns=" + Chr(34) +
"http://tempuri.org/SoapServer/Service1" + Chr(34) + " />" & _
"</soap:Body>" & _
"</soap:Envelope>"

objHttpRequest =
WebRequest.Create("http://localhost/SoapServer/Service1.asmx")
objHttpRequest.Method = "POST"
objHttpRequest.ContentType = "text/xml"
objHttpRequest.ContentLength = sTmp.Length
objHttpRequest.Headers.Add("SOAPAction",
"http://tempuri.org/SoapServer/Service1/HelloWorld")

myWriter = New StreamWriter(objHttpRequest.GetRequestStream())
myWriter.Write(sTmp)

objHttpResponse = objHttpRequest.GetResponse
objResponseStream = New
StreamReader(objHttpResponse.GetResponseStream())
sResult = objResponseStream.ReadToEnd
objResponseStream.Close()

================================================== ===============
================================================== ===============

the code fails at objHttpResponse = objHttpRequest.GetResponse, an
exception is thrown stating the request timed out.

pointers appreciated..

thanks in advance
Jul 13 '06 #2

P: n/a
You may find the information at the link below userful:

http://www.w3coder.com/ws/HttpWebRequest.aspx

Mike McIntytre [MVP]
www.getdotnetcode.com

"hharry" <pa*********@nyc.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
hello all,

trying to consume a simple web service using httpwebrequest instead of
generating a proxy class.

code for simple web service:

Imports System.Web.Services

<System.Web.Services.WebService(Namespace :=
"http://tempuri.org/SoapServer/Service1")_
Public Class Service1
Inherits System.Web.Services.WebService

<WebMethod()_
Public Function HelloWorld() As String
Return "Hello World"
End Function
End Class

code to consume web service using httpwebrequest object:

Dim sTmp As String
sTmp = "" & _
"<?xml version=" + Chr(34) + "1.0" + Chr(34) + " encoding="
+ Chr(34) + "utf-8" + Chr(34) + "?>" & _
"<soap:Envelope xmlns:xsi=" + Chr(34) +
"http://www.w3.org/2001/XMLSchema-instance" + Chr(34) + " xmlns:xsd=" +
Chr(34) + "http://www.w3.org/2001/XMLSchema" + Chr(34) + " xmlns:soap="
+ Chr(34) + "http://schemas.xmlsoap.org/soap/envelope/" + Chr(34) + ">"
& _
"<soap:Body>" & _
"<HelloWorld xmlns=" + Chr(34) +
"http://tempuri.org/SoapServer/Service1" + Chr(34) + " />" & _
"</soap:Body>" & _
"</soap:Envelope>"

objHttpRequest =
WebRequest.Create("http://localhost/SoapServer/Service1.asmx")
objHttpRequest.Method = "POST"
objHttpRequest.ContentType = "text/xml"
objHttpRequest.ContentLength = sTmp.Length
objHttpRequest.Headers.Add("SOAPAction",
"http://tempuri.org/SoapServer/Service1/HelloWorld")

myWriter = New StreamWriter(objHttpRequest.GetRequestStream())
myWriter.Write(sTmp)

objHttpResponse = objHttpRequest.GetResponse
objResponseStream = New
StreamReader(objHttpResponse.GetResponseStream())
sResult = objResponseStream.ReadToEnd
objResponseStream.Close()

================================================== ===============
================================================== ===============

the code fails at objHttpResponse = objHttpRequest.GetResponse, an
exception is thrown stating the request timed out.

pointers appreciated..

thanks in advance

Jul 13 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.