Resolved Call Web Service

lfields20

Member
Joined
Sep 12, 2009
Messages
13
Programming Experience
1-3
I'm trying to send a string from an XML to a ASP.NET web service, which will then convert that string to XML and saves it locally. I have everything working except for when I try to call the web service by the code below, I get the following error:

The remote server returned an error: (500) Internal Server Error.

Try
            'Loads the XML file and converts to string
            Dim rtnString As String
            rtnString = File.ReadAllText(ConfigurationManager.AppSettings("getXML"), Text.ASCIIEncoding.Default)

            'Sends string to outside client's web service
            Dim url As String = "http://localhost/JAMIIS_rcv_FILE.asmx/receiveString"

            Dim postData As String = rtnString

            Dim objRequest As WebRequest = WebRequest.Create(url)
            objRequest.Method = "POST"
            objRequest.Credentials = CredentialCache.DefaultCredentials
            objRequest.ContentLength = postData.Length
            objRequest.ContentType = "text/plain"

            Dim postWriter As New StreamWriter(objRequest.GetRequestStream())
            postWriter.Write(postData)
            postWriter.Close()

            Dim objResponse As WebResponse = objRequest.GetResponse()
            Dim sr As New StreamReader(objResponse.GetResponseStream())
            Dim rawOutput As String = sr.ReadToEnd()
            sr.Close()
        Catch ex As Exception
            Response.Write(ex.Message)
        End Try


Any ideas to hit the web service with the internal error message?

Thanks
 
Last edited:
UPDATE:

I am calling the web service. I was getting an internal error 500 message because the web service is looking for a variable being name "txtString".

Now that I found this out, in the HttpWebRequest method, how can I set the variable name of the string that is being passed into the web service?
 
Ok, I figured out the name part.

Dim postData As String = rtnString should be Dim postData As String = "txtString=" & rtnString where txtString is the parameter of the web service.

I also had to change objRequest.ContentType = "text/plain" to objRequest.ContentType = "application/x-www-form-urlencoded"

With those changes, it's working right.
 

Latest posts

Back
Top