dotnet / WatsonWebserver

Watson is the fastest, easiest way to build scalable RESTful web servers and services in C#.
MIT License
411 stars 84 forks source link

Watson.Lite : C# web-clients not working out of the box with the server. #136

Closed GitHubProUser67 closed 4 months ago

GitHubProUser67 commented 9 months ago

In Watson.Lite, using a stock configured C# downloader as this function does:

image

Will always return a internal server error on the server:

image

jchristn commented 9 months ago

What are you passing in for ip, port, and command?

GitHubProUser67 commented 8 months ago

So, the system is this.

I pass in the server ip, port 10076, and the command which is a CRUD command.

BUT, I managed to fix the bug, if fact, server needs to be able to attribute default values for the method and content type:

image

Ideally it should default to GET / text/plain.

jchristn commented 4 months ago

Sorry for the delay here, I can't reproduce this using the Test.Default project and v6.1.9.

Your first example:

        public static void Main(string[] args)
        {
            HttpResponseMessage resp = new HttpClient().GetAsync("http://localhost:8080/").Result;
            Console.WriteLine(SerializationHelper.SerializeJson(resp, true));
        }

Returns:

C:\Code\Misc\Sandbox\sandbox\bin\Debug\net8.0>sandbox
{
  "Version": "1.1",
  "Content": {
    "Headers": [
      {
        "Key": "Content-Type",
        "Value": [
          "text/plain"
        ]
      },
      {
        "Key": "Content-Length",
        "Value": [
          "13"
        ]
      }
    ]
  },
  "StatusCode": "OK",
  "ReasonPhrase": "OK",
  "Headers": [
    {
      "Key": "Date",
      "Value": [
        "Sun, 30 Jun 2024 18:32:57 GMT"
      ]
    },
    {
      "Key": "Connection",
      "Value": [
        "close"
      ]
    },
    {
      "Key": "Access-Control-Allow-Origin",
      "Value": [
        "*"
      ]
    },
    {
      "Key": "Access-Control-Allow-Methods",
      "Value": [
        "OPTIONS, HEAD, GET, PUT, POST, DELETE, PATCH"
      ]
    },
    {
      "Key": "Access-Control-Allow-Headers",
      "Value": [
        "*"
      ]
    },
    {
      "Key": "Access-Control-Expose-Headers",
      "Value": [
        ""
      ]
    },
    {
      "Key": "Accept",
      "Value": [
        "*/*"
      ]
    },
    {
      "Key": "Accept-Language",
      "Value": [
        "en-US, en"
      ]
    },
    {
      "Key": "Accept-Charset",
      "Value": [
        "ISO-8859-1, utf-8"
      ]
    },
    {
      "Key": "Cache-Control",
      "Value": [
        "no-cache"
      ]
    },
    {
      "Key": "Host",
      "Value": [
        "localhost:8080"
      ]
    }
  ],
  "TrailingHeaders": [],
  "RequestMessage": {
    "Version": "1.1",
    "VersionPolicy": "RequestVersionOrLower",
    "Method": {
      "Method": "GET"
    },
    "RequestUri": "http://localhost:8080/",
    "Headers": [],
    "Properties": {},
    "Options": {}
  },
  "IsSuccessStatusCode": true
}

Your second example:

            string resp = new WebClient().DownloadStringTaskAsync("http://localhost:8080/").Result;
            Console.WriteLine(resp);

Returns:

C:\Code\Misc\Sandbox\sandbox\bin\Debug\net8.0>sandbox
Default route