473,387 Members | 1,453 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,387 software developers and data experts.

Call WebService using HTTPWebRequest object

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" & _
" 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>" & _
" <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!

Dec 11 '05 #1
4 3311
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 "

Dec 11 '05 #2
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.

Dec 11 '05 #3
> 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

Dec 11 '05 #4
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".

Dec 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Toma Marinov | last post by:
Hello ! I have a WebService. When I execute WS in browser on local machine - its OK! When I execute WS in browser on the server machine /with remote desktop/ - its OK! When I execute WebService...
2
by: Toma Marinov | last post by:
Hello ! I have a WebService. When I execute WS in browser on local machine - its OK! When I execute WS in browser on the server machine /with remote desktop/ - its OK! When I execute WebService...
0
by: Raymondr | last post by:
Hi, First a brief description of out application: We have a webapplication which calls a couple of webservices during one request (postback). These calls to the webservices are made concurrent...
6
by: plork | last post by:
hi all i'm calling a web service method and can get it's results just fine however i want to grab the repsonse message from the call is anyone able to tell me how i do this? results =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.