Go Back   Access World Forums > Apps and Windows > VB.NET

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 09-04-2018, 01:37 AM   #1
Tfa
Newly Registered User
 
Join Date: Nov 2016
Location: Greece Athens
Posts: 32
Thanks: 5
Thanked 1 Time in 1 Post
Tfa is on a distinguished road
connection error with webserver

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 by Tfa; 09-04-2018 at 01:50 AM.
Tfa is offline   Reply With Quote
Old 09-04-2018, 02:57 AM   #2
Gasman
Access newbie
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 2,587
Thanks: 308
Thanked 402 Times in 387 Posts
Gasman has a spectacular aura about Gasman has a spectacular aura about
Re: connection error with webserver

Windows update?
__________________
Access novice. Sometimes trying to give something back.
Access 2007
Gasman is online now   Reply With Quote
Old 09-04-2018, 03:00 AM   #3
Tfa
Newly Registered User
 
Join Date: Nov 2016
Location: Greece Athens
Posts: 32
Thanks: 5
Thanked 1 Time in 1 Post
Tfa is on a distinguished road
Re: connection error with webserver

there was one about 5 days ago but the problem occured 2 to 3 days after the update

Tfa is offline   Reply With Quote
Old 09-04-2018, 03:05 AM   #4
Gasman
Access newbie
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 2,587
Thanks: 308
Thanked 402 Times in 387 Posts
Gasman has a spectacular aura about Gasman has a spectacular aura about
Re: connection error with webserver

Check the update log?
__________________
Access novice. Sometimes trying to give something back.
Access 2007
Gasman is online now   Reply With Quote
Old 09-05-2018, 04:49 AM   #5
Tfa
Newly Registered User
 
Join Date: Nov 2016
Location: Greece Athens
Posts: 32
Thanks: 5
Thanked 1 Time in 1 Post
Tfa is on a distinguished road
Re: connection error with webserver

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

Tfa is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Connect Access 2010 to a webserver Gijs Access Web 4 10-27-2015 09:42 AM
connecting with a mysql back end in a webserver, is it possible? icemonster SQL Server 2 10-31-2011 08:29 AM
Updating a Table on a webserver cdoyle General 0 07-13-2007 07:20 AM
VBA Grab some data from a webserver? deBassMan Modules & VBA 2 09-23-2006 01:38 PM
Connecting to a DB on a webserver in Excel The Stoat Excel 5 12-02-2005 07:49 AM




All times are GMT -8. The time now is 04:16 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World