Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15605

VS 2019 Async webmethod from frontend

$
0
0
Code:

    <System.Web.Services.WebMethod()>
    Public Shared Async Function TestAjaxCall(ByVal url As String) As Threading.Tasks.Task(Of Boolean)
        Using client = New HttpClient()
            client.BaseAddress = New Uri(url)
            client.DefaultRequestHeaders.Accept.Clear()
            client.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue("application/json"))
            Dim response As HttpResponseMessage = Await client.GetAsync("/api/v1/accounts")
            If response.IsSuccessStatusCode Then
                Return True
            Else
                Return False
            End If
        End Using
    End Function

Got the above code that I need to call from front end that is plugged into the asp.net project. Needs to be done like this for CORS reasons that we cannot change.

I am calling the code like so
Code:

    fetch('http://localhost:27578/organisation/manage/manage.aspx/TestAjaxCall', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ url: 'https://test.instructure.com' }),
    })
      .then(response => response.json())
      .then(parsedJson => console.log(parsedJson.d))
      .catch(err => setCheckConnection(false));
  }, []);

It worked when my TestAjaxCall was not async and returning a simple boolean and not passing a body to it. But now it just in the network tab sits as pending. I put a breakput on the response if statement but it never gets hit just keeps pending. Any ideas would be great! I'll update with other trials that i attempt. Not sure if TestAjaxCall is mean't to be POST maybe?

Viewing all articles
Browse latest Browse all 15605

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>