Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Call WebService using HTTPWebRequest object

Reply
Thread Tools

Call WebService using HTTPWebRequest object

 
 
hharry
Guest
Posts: n/a
 
      12-11-2005
Hi All,


I have a simple web service:


<WebMethod()> _
Public Function ReSample(ByVal sInput As Integer) As String


Return sInput * 5


End Function


I am trying to call this service from a second service by sending a
soap message using the HTTPWebRequest object.


Public Function CallReSample(ByVal y As Integer) As String


Dim SoapEnv As String = ""
Dim url As String =
"http://localhost/AcxiomRequest/Service1.asmx/ReSample"
Dim result As String = ""
Dim myWriter As StreamWriter


SoapEnv = "" & _
"<soap:Envelope" & _
" xmlnssi=" + Chr(34) +
"http://www.w3.org/2001/XMLSchema-instance" + Chr(34) & _
" xmlnssd=" + Chr(34) +
"http://www.w3.org/2001/XMLSchema" + Chr(34) & _
" xmlns:soap=" + Chr(34) +
"http://schemas.xmlsoap.org/soap/envelope/" + Chr(34) + ">" & _
" <soap:Body>" & _
" <ReSample xmlns:m=" + Chr(34) +
"http://tempuri.org/message/" + Chr(34) + ">" & _
"<sInput>50</sInput>" & _
" </ReSample>" & _
" </soap:Body>" & _
" </soap:Envelope>"


Dim objRequest As HttpWebRequest = WebRequest.Create(url)


If Not objRequest Is Nothing Then
objRequest.Method = "POST"
objRequest.ContentLength = SoapEnv.Length
objRequest.ContentType =
"application/x-www-form-urlencoded"


objRequest.Headers.Add("SOAPAction", "ReSample")


myWriter = New StreamWriter(objRequest.GetRequestStream())
myWriter.Write(SoapEnv)


If Not myWriter Is Nothing Then
myWriter.Close()
End If


Dim objResponse As HttpWebResponse
Dim esr As StreamReader


Try
objResponse = objRequest.GetResponse()
Catch ex As WebException 'Exception
esr = New StreamReader(ex.Response.GetResponseStream())

result = esr.ReadToEnd()
Catch ex As Exception


End Try


Dim sr As StreamReader
sr = New StreamReader(objResponse.GetResponseStream())
result = sr.ReadToEnd()
sr.Close()


objResponse.Close()
sr.Close()
objResponse = Nothing
sr = Nothing
objRequest.Abort()
End If


objRequest = Nothing
myWriter = Nothing


End Function


////////////////////////////////////////////////////////////////////////



I keep getting the following error:


System.InvalidOperationException: Missing parameter: sInput.


I'm not sure how to include a parameter in the soap envelope.


Pointers appreciated


Thanks in advance!

 
Reply With Quote
 
 
 
 
prabhupr@hotmail.com
Guest
Posts: n/a
 
      12-11-2005
Your return datatype is STRING in "Public Function ReSample(ByVal
sInput As Integer) As String "
May be you need to explicitly conver the type within the code "Return
sInput * 5 "

 
Reply With Quote
 
 
 
 
hharry
Guest
Posts: n/a
 
      12-11-2005
Thanks.

I changed my web method to:

<WebMethod()> _
Public Function ReSample(ByVal sInput As String) As String

Return sInput

End Function

So, I would expect the service to return the string "50", but still
getting the missing parameter exception.
I'm sure there is something missing from my soap envelope string.

 
Reply With Quote
 
Jarod
Guest
Posts: n/a
 
      12-11-2005
> So, I would expect the service to return the string "50", but still
> getting the missing parameter exception.
> I'm sure there is something missing from my soap envelope string.
>


Go to your webservice address through browser or in debug mode you have some
test site that presents you SOAP request that you should use, just copy it.
For example http://localhost/yourwebservice/thisservice.asmx and put it in
the browser.
Jarod

 
Reply With Quote
 
hharry
Guest
Posts: n/a
 
      12-12-2005
Thanks Jarod.

This pointed me in the right direction. My namespace was incorrect and
the content-type should have been "text/xml; charset=utf-8" as opposed
to "application/x-www-form-urlencoded".

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Asynchronous Call of WebService method within a WebService RenÚ Preu▀ler ASP .Net Web Services 0 10-29-2008 11:55 AM
.Net 2.0 issue with HttpWebRequest/Proxy breaking WebService LarryKuperman ASP .Net 2 05-13-2008 12:56 PM
Error connection using webservice locally (3 webservice in balanci Roberto Giorgetti ASP .Net Web Services 0 06-13-2006 06:40 PM
Problem to call a WEBSERVICE in another WEBSERVICE (AXIS/ TOMCAT) Cyril Java 2 06-01-2006 06:07 PM
Call Web Service using HTTPWebRequest hharry ASP .Net Web Services 1 12-12-2005 04:55 PM



Advertisments