473,738 Members | 11,192 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(By Val 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.Crea te(url)
If Not objRequest Is Nothing Then
objRequest.Meth od = "POST"
objRequest.Cont entLength = SoapEnv.Length
objRequest.Cont entType =
"applicatio n/x-www-form-urlencoded"
objRequest.Head ers.Add("SOAPAc tion", "ReSample")
myWriter = New StreamWriter(ob jRequest.GetReq uestStream())
myWriter.Write( SoapEnv)
If Not myWriter Is Nothing Then
myWriter.Close( )
End If
Dim objResponse As HttpWebResponse
Dim esr As StreamReader
Try
objResponse = objRequest.GetR esponse()
Catch ex As WebException 'Exception
esr = New StreamReader(ex .Response.GetRe sponseStream())

result = esr.ReadToEnd()
Catch ex As Exception
End Try
Dim sr As StreamReader
sr = New StreamReader(ob jResponse.GetRe sponseStream())
result = sr.ReadToEnd()
sr.Close()
objResponse.Clo se()
sr.Close()
objResponse = Nothing
sr = Nothing
objRequest.Abor t()
End If
objRequest = Nothing
myWriter = Nothing
End Function
////////////////////////////////////////////////////////////////////////

I keep getting the following error:
System.InvalidO perationExcepti on: 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 3333
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 "applicatio n/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
1891
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 in WindowsForms app on the local machine /app and WS/ - its OK ! But when I execute the Web service/server machine/ from WindowsForms app /local machine/, it gives me this error :
2
321
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 in WindowsForms app on the local machine /app and WS/ - its OK ! But when I execute the Web service/server machine/ from WindowsForms app /local machine/, it gives me this error :
0
1625
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 using asynchronous webservices calls. The number of webservices called concurrent is between 1 and 18. The webservice calls are made using SSL with a X509 clientcertificate. The application is underhigh load
6
18239
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 = service.getMethod(a, b, c, d) then iterating through for (int i = 0; i < results .Length; i++)
0
8788
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9476
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9335
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9208
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8210
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2745
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.