Results 1 to 3 of 3

Thread: webservice response giving problem

  1. #1
    keroed1 Guest

    Default webservice response giving problem

    i created a simple webservice

    Code:
    <WebMethod()> _
        Public Function HelloWorld(ByVal person As String) As String
            Return "Hello" + person
        End Function
    andi created a vb.net application that i jus wanted to post the name and get back the response

    Code:
    ' Create the web request  
            request = DirectCast(WebRequest.Create("http://localhost:80/WebService_RPC2"), HttpWebRequest)
    
            ' Set type to POST  
            request.Method = "POST"
            request.ContentType = "application/x-www-form-urlencoded"
    
            ' Create a byte array of the data we want to send  
            byteData = System.Text.UTF8Encoding.UTF8.GetBytes(data.ToString())
    
            ' Set the content length in the request headers  
            request.ContentLength = data.Length
    
            ' Write data  
            Try
                postStream = request.GetRequestStream()
                postStream.Write(byteData, 0, byteData.Length)
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            Finally
                If Not postStream Is Nothing Then postStream.Close()
            End Try
    
            Try
                ' Get response  
                response = DirectCast(request.GetResponse(), HttpWebResponse)
    
                ' Get the response stream into a reader  
                reader = New StreamReader(response.GetResponseStream())
    
                ' Console application output  
                Console.WriteLine(reader.ReadToEnd())
            Catch ex As Exception
                MessageBox.Show(ex.Message)
    
            Finally
                If Not response Is Nothing Then response.Close()
            End Try
    
            Dim responseString As String = Convert.ToString(reader)
    but this doesn't work when i debug the code i see that the request goes through and no exception is thrown as soon as i try to read the response
    Code:
    response = DirectCast(request.GetResponse(), HttpWebResponse)
    i get an exceptiong is thrown saying
    the remote server return an error405)Method Not allowed
    can anyone tell me what i am doing wrong is there something i am not doing correcly from the webservice side?

  2. #2
    Join Date
    Jun 2003
    Posts
    96
    Rep Power
    0

    Default

    In the web.config file, just before the </system.web> put (copy)



    <webServices>

    <protocols>

    <add name="HttpGet"/>

    <add name="HttpPost"/>

    </protocols>

    </webServices>



    So at the end of it all it should look like



    <webServices>

    <protocols>

    <add name="HttpGet"/>

    <add name="HttpPost"/>

    </protocols>

    </webServices>

    </system.web>

  3. #3
    keroed1 Guest

    Default

    i got it to work the sample code i used above actually works its jus that i needed a secure connection to do the post

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •