Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / December 2005

Tip: Looking for answers? Try searching our database.

Call Web Service using HTTPWebRequest

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
hharry - 09 Dec 2005 20:50 GMT
Hi All,

I have asimple 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!
hharry - 12 Dec 2005 16:55 GMT
Figured it out.

Did not have the correct namespace for the service and the content type
is "text/xml; charset=utf-8" as opposed to
"application/x-www-form-urlencoded".

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.