473,396 Members | 2,098 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

consume web service via httpwebrequest

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
2 6012
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Michael Hatmaker | last post by:
I have begun experimenting with web services, and I created some simple web services in C# and was able to install them with IIS and create an equally simple C# client to consume them. My next...
2
by: Abeslom via .NET 247 | last post by:
Hi, I am trying to create a simple .NET http-Get client that willconsume a java webservice on a mainframe. If I type the URL forthe webservice in the Browser, the service works and I get theexpected...
4
by: John Bailo | last post by:
I wrote a .NET/c# webservice which I then needed to consume from java server pages. The simplest ( and best ) solution I found, was some code to open a socket, and send a SOAP message directly...
0
by: Seth | last post by:
For some reason my service works fine except that it will create the file in my c drive, but will not write to the file. Sorry if this is a duplicate post, i have found some that ask the same...
7
by: Jamie Phillips | last post by:
I'm sure this topic has been "around the block" a few times, but I have not been able to find ANY solutin that fits this particular problem. I have written a Java Axis web service that has a method...
0
by: leslie_tighe | last post by:
Hello, I have a set of web services running on Java server that are exposed through axis 1.2.1. I can invoke these services in browser and through a java test client. However, when I try to...
5
by: David Lozzi | last post by:
Howdy, I wrote a web service in .Net for my customer. My customer has another vendor who now has to consume it but they are not using Visual Studio. Most of their pages are jsp, and they said...
3
by: frustratedcoder | last post by:
I need to consume a web service written in Perl but there is no wsdl file for this service. The perl soap client that can call and consume this web service looks like this (if it helps) #!perl...
7
by: GD | last post by:
Hi, I am trying to call a webservice from a windows service application. It works only if I launch the windows service app from VS.Net 2005 (Worked around from Main()) or from a winform test...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.