Click here to Skip to main content
15,892,927 members

Rest server response error 500

Member 10103170 asked:

Open original thread
Hi,
I'm setting up a website to act as our API to our internal database.
I think I'm going in the right direction but keep hitting a brick wall.
Server code and my test routine below.
Error2 = ProtocolError
Any pointers to resolve would be greatly appreciated!
Paul

What I have tried:

NOTE:
Just Added:
<system.web>
  <webServices>
    <protocols>
      <add name="HttpGet"/>
      <add name="HttpPost"/>
    </protocols>
  </webServices>
</system.web>

to Webserver config.
Now:
https://WEBSITE/service.asmx/TestRest
Returns:
<?xml version="1.0" encoding="UTF-8"?>
<string xmlns="http://localhost:51561/APIServer/">{"qtest":{"response":"hello"}}</string>

Getting better but my test site still fails. Same error as below.





Server Code: Service.vb file:

<WebService(Namespace:="http://localhost:51561/APIServer/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Service
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function TestRest() As String

        Dim sjon As String = "{"
        sjon = sjon & """qtest"":{""response"":""hello""}"
        sjon = sjon & "}"

        Return sjon
    End Function
End Class

Service.asmx file:
<%@ WebService Language="vb" CodeBehind="~/App_Code/Service.vb" Class="Service" %>


Calling the Webserver with this:

        Dim returnedData As String = ""
        Dim error2 As String = ""

        Try

            Dim DataToSend As String = ""
 

            Dim urlLive As String = "https://WEBSITENAME/Service.asmx/TestRest"  

            Dim postAddress = New Uri(urlLive)

            Dim request = DirectCast(WebRequest.Create(postAddress), HttpWebRequest)

            request.Method = "POST"
            request.ContentType = "application/json"  

            request.Headers.Add("AcceptTypes", "text/plain")
            request.Headers.Add("Accept-Language", "en-US")
            request.Headers.Add("UserAgent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)")

            request.ContentLength = Len(DataToSend).ToString
 

            request.ProtocolVersion = HttpVersion.Version11

            Dim postByteData As Byte() = System.Text.UTF8Encoding.UTF8.GetBytes(DataToSend)
            request.ContentLength = postByteData.Length

            Using postStream As Stream = request.GetRequestStream()
                postStream.Write(postByteData, 0, postByteData.Length)
            End Using

            Using resp = TryCast(request.GetResponse(), HttpWebResponse)
                Dim reader = New StreamReader(resp.GetResponseStream())
                returnedData = reader.ReadToEnd()
            End Using

        Catch exw As WebException

            Try
                Dim httpResponse As HttpWebResponse = CType(exw.Response, HttpWebResponse)
                returnedData = "Error - " & CInt(httpResponse.StatusCode).ToString() & " - " & httpResponse.StatusCode.ToString()

                error2 = exw.Status.ToString

            Catch ex As Exception
                returnedData = "Error - Site"
            End Try

        Catch ex As Exception

            returnedData = "Error - Exception Error"

        End Try

        error2 = error2 & ""
        returnedData = returnedData & ""
Tags: Visual Basic, ASP.NET, REST, ASMX, HTTPS

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900