• ** There has been a recent site upgrade. Please clear your browser cache to avoid issues. **
  • New forum feature - post voting and best solution

    Check out this thread for the details: https://www.access-programmers.co.uk/forums/threads/new-forum-feature-post-voting-and-best-answer.314134/

    This new feature looks great to me! :)

  • We now have 3 forum themes

    Go for the default (light) theme, Shades of Grey or Shades of Blue. I just added the Blue one.

    The thread about it is here: https://www.access-programmers.co.uk/forums/threads/new-forum-theme-shades-of-blue.314136/

connection error with webserver (1 Viewer)

Tfa

Registered User.
Local time
Today, 02:29
Joined
Nov 29, 2016
Messages
32
hello again
i need your help
i made a simple app that calls a webmethod and gets a json string as response
everything worked fine up untill yesterday when suddenlly it stop working for no reason
when the code tries to get the response the message i get is
"A first chance exception of type 'System.Net.WebException' occurred in System.dll"

what i dont understand is why did it stop working in both the form app i made and a dll that i use to a different project the code and libraries used in both of them are exacly the same and no change was made for the last 3 months
here is the code

Code:
Imports System.Net
Imports System.IO
Imports System.Text
Imports Newtonsoft.Json
Imports System.Web

Public Class Form1


    Public Class Get_all_closed_bills_class
        Property ClientToken As String
        Property AccessToken As String
        Property StartUtc As String
        Property EndUtc As String
    End Class

    Public Function Get_all_closed_bills(Request As String,
                                        Username As String,
                                        Password As String,
                                        AccessToken As String,
                                        ClientToken As String,
                                        StartUtc As String,
                                        EndUtc As String)
        Dim strRequest As String = Request
        Dim strJsonData As String
        Dim objhttpWebRequest As HttpWebRequest
        Dim obj_Get_all_closed_bills As New Get_all_closed_bills_class

        obj_Get_all_closed_bills.ClientToken = ClientToken
        obj_Get_all_closed_bills.AccessToken = AccessToken
        obj_Get_all_closed_bills.StartUtc = StartUtc
        obj_Get_all_closed_bills.EndUtc = EndUtc


        strJsonData = JsonConvert.SerializeObject(obj_Get_all_closed_bills, Newtonsoft.Json.Formatting.Indented)

        Try
            Dim MyCredentials As System.Net.NetworkCredential
            MyCredentials = New System.Net.NetworkCredential(Username, Password)
            Dim httpWebRequest = DirectCast(WebRequest.Create(strRequest), HttpWebRequest)
            httpWebRequest.Credentials = MyCredentials
            httpWebRequest.ContentType = "application/json"
            httpWebRequest.Method = "POST"

            Using streamWriter = New StreamWriter(httpWebRequest.GetRequestStream())
                streamWriter.Write(strJsonData)
                streamWriter.Flush()
                streamWriter.Close()
            End Using
            objhttpWebRequest = httpWebRequest
        Catch ex As Exception
            Console.WriteLine("Send Request Error[{0}]", ex.Message)
            Return Nothing
        End Try

        Return GetResponse(objhttpWebRequest)


    End Function


    Private Function GetResponse(ByVal httpWebRequest As HttpWebRequest) As String
        Dim strResponse As String = "Bad Request:400"
        Try
            Dim httpResponse = DirectCast(httpWebRequest.GetResponse(), HttpWebResponse)
            Using streamReader = New StreamReader(httpResponse.GetResponseStream())
                Dim result = streamReader.ReadToEnd()
                strResponse = result.ToString()
            End Using
        Catch ex As Exception
            Console.WriteLine("GetResponse Error[{0}]", ex.Message)
            Return ex.Message
        End Try
        Return strResponse

    End Function



    Private Sub btnRetrieve_Click(sender As System.Object, e As System.EventArgs) Handles btnRetrieve.Click
        Dim strResponse As String

        ' request 
        ' username
        ' password
        ' AccessToken
        ' ClientToken
        ' StartUtc
        ' EndUtc
        
        'strResponse = 
        Dim start_date As String = Format(StartDate.Value, "yyyy-MM-ddThh:mm:ss.00Z")



        Dim end_date As String = Format(EndDate.Value, "yyyy-MM-ddThh:mm:ss.00Z")




        strResponse = Get_all_closed_bills("https://demo.mews.li/api/connector/v1/bills/getAllClosed", _
                                                         "connector-api@mews.li", _
                                                         "connector-api", _
                                                         "C66EF7B239D24632943D115EDE9CB810-EA00F8FD8294692C940F6B5A8F9453D", _
                                                            "E0D439EE522F44368DC78E1BFB03710C-D24FB11DBE31D4621C4817E028D9E1D", _
                                                            start_date, _
                                                            end_date)

  

        TextBox1.Text = strResponse
       
    End Sub





End Class

as soon as the code get to :
Dim httpResponse = DirectCast(httpWebRequest.GetResponse(), HttpWebResponse)

i get the "A first chance exception of type 'System.Net.WebException' occurred in System.dll" error
 
Last edited:

Tfa

Registered User.
Local time
Today, 02:29
Joined
Nov 29, 2016
Messages
32
there was one about 5 days ago but the problem occured 2 to 3 days after the update
 

Gasman

Enthusiastic Amateur
Local time
Today, 00:29
Joined
Sep 21, 2011
Messages
6,837
Check the update log?
 

Tfa

Registered User.
Local time
Today, 02:29
Joined
Nov 29, 2016
Messages
32
there was a windows update for net framework 4.7.3 i think i removed but the problem wasn't solved
i forgot to mention that the application wasz build in VS 2010
and net framework 4.0
i made a new app in my laptop at vs 2017 build it and it run smoothly took the exe run it to the office computer and it worked
i made the same app back to the office computer and i got the same error again
 

Users who are viewing this thread

Top Bottom