logo

The ConnectWise Control forum has moved to ConnectWise University! This forum has been locked and is in read-only mode. Click here for instructions on how to access the new forum.

Welcome Guest! You can not login or register.

Notification

Icon
Error

Options
Go to last post Go to first unread
ditkar  
#1 Posted : Monday, January 5, 2015 9:30:21 AM(UTC)
ditkar


Rank: Advanced Member

Joined: 7/9/2014(UTC)
Posts: 88
Man
United States

Thanks: 8 times
I am trying to integrate SC with my VB.Net application. I am using http and json. I have listed out some of the functions that I am using in my project. However, when I try to call anyone of these in the Prodution environment, I get an error msg "Time Out" or "500 Internal Server Error" etc. Is there any better way of doing this? Could someone possibly shed some light here.

The main purpose of building these function is to create a Session Queuing system(which is not there in SC 4.4 as well as 5.0). I have programmed the Queuing system where in an Advisor is able to transfer a current session to a particular Queue(a Session Group). And the advisor at the other end can pick the same transferred Queue. The only problem is with the connectivity with the SC server. The request sent most of the time results in the error, as mentioned above. Not sure what am I doing wrong.

Here is the sample code...


Code:

'...................................................
'To Create a Session using Simple Code
'...................................................
jVsessionID = JsonConvert.DeserializeObject(Of JValue)(ClsCommonClasses.HttpPost(lsScrnCntURL & Var.tmpStr, JsonConvert.SerializeObject(New [Object]() {0, lsCustName, False, ScrPIN, ScrParam}), UserName, ScrPass))


'...................................................
'To Get All Sessions from the server
'...................................................
Private Function SCGetHostSessionInfo(ByVal lsLocalUser As Boolean) As JObject
        Dim vdt As New DataTable
        Dim StrSessionInfo As JValue
        StrSessionInfo = HttpPost(LoginURL & "/Service.ashx/GetHostSessionInfo", buildHostSessionInfoParam(vbNull))
        ''Return JsonConvert.DeserializeObject(Of IDictionary(Of String, String))(StrSessionInfo)
        Dim Obj As JObject = JsonConvert.DeserializeObject(Of JObject)(StrSessionInfo)
        Return Obj
End Function

'...................................................
'To Transfer a Session
'...................................................
Private Function SCTransferSession(ByVal sessionGroupName As String, ByVal sessionIDs As Guid(), ByVal toHost As String) As String
        Dim vdt As New DataTable
        Dim StrSessionInfo As String
        StrSessionInfo = HttpPost(LoginURL & "/Service.ashx/TransferSessions", JsonConvert.SerializeObject(New [Object]() {sessionGroupName, sessionIDs, toHost}), lsAdminId, lsAdminPwd)
        Return StrSessionInfo
End Function

'...................................................
'To Get Sessions Details 
'...................................................
Private Function SCGetSessionDetails(ByVal sessionGroupName As String, ByVal sessionID As Guid) As JObject
        Dim vdt As New DataTable
        Dim StrSessionInfo As String
        StrSessionInfo = HttpPost(LoginURL & "/Service.ashx/GetSessionDetails", JsonConvert.SerializeObject(New [Object]() {sessionGroupName, sessionID}), lsAdminId, lsAdminPwd)
        Dim Obj As JObject = JsonConvert.DeserializeObject(Of JObject)(StrSessionInfo)
        Return Obj
End Function

'...................................................
'To Get Sessions Details 
'...................................................
Private Function SCUpdateSession(ByVal sessionGroupName As String, ByVal sessionIDs As Guid(), ByVal Names As String(), ByVal ispublic As Boolean(), ByVal codes As String(), ByVal CustomProperty(,) As String) As String
        Dim vdt As New DataTable
        Dim StrSessionInfo As String
        StrSessionInfo = HttpPost(LoginURL & "/Service.ashx/UpdateSessions", JsonConvert.SerializeObject(New [Object]() {sessionGroupName, sessionIDs, Names, ispublic, codes, CustomProperty}), lsAdminId, lsAdminPwd)
        Return StrSessionInfo
End Function



'...................................................
'HTTPPost:
'...................................................
Public Shared Function HttpPost(ByVal url As [String], ByVal Parameters As String, ByVal UserId As String, ByVal Pwd As String) As String
        Dim req As HttpWebRequest = DirectCast(HttpWebRequest.Create(url), HttpWebRequest)
        req.UserAgent = "ScreenConnect Integration Library"
        req.Timeout = 10000
        req.Credentials = New NetworkCredential(UserId, Pwd) 'nc
        req.ContentType = "application/x-www-form-urlencoded"
        req.Method = "POST"
        Dim bytes As Byte() = System.Text.Encoding.ASCII.GetBytes(Parameters)
        req.ContentLength = bytes.Length
        Dim os As System.IO.Stream = req.GetRequestStream()
        os.Write(bytes, 0, bytes.Length)
        os.Close()
        Dim resp As System.Net.WebResponse = req.GetResponse()
        If resp Is Nothing Then
            Return Nothing
        End If
        Dim sr As New System.IO.StreamReader(resp.GetResponseStream())
        Dim respStr As [String] = sr.ReadToEnd().Trim()
        Return respStr
    End Function

Alexander  
#2 Posted : Monday, January 5, 2015 4:06:12 PM(UTC)
Alexander


Rank: Administration

Medals: Level 3: Shirt off your back! Received 25 Thanks!

Joined: 7/23/2013(UTC)
Posts: 715
Man
Location: Raleigh, NC

Was thanked: 66 time(s) in 63 post(s)
Your content type should probably be application/json rather than application/x-www-form-urlencoded, since you're sending JSON data rather than form data; I don't know if that's what's causing the problem, though.
Do you get the same error if you send the request with curl or something? (I often use this Chrome app to test POST requests.)
ScreenConnect Team
ditkar  
#3 Posted : Tuesday, January 6, 2015 1:57:25 PM(UTC)
ditkar


Rank: Advanced Member

Joined: 7/9/2014(UTC)
Posts: 88
Man
United States

Thanks: 8 times
The existing code works fine but its just the time that it takes is what concerns me. This same code works fine in my development environment but when I try it on Production with 10+ remote sessions active the code tends to freeze the .net application.
Can we have a call to discuss in details.
Alexander  
#4 Posted : Wednesday, January 7, 2015 3:36:45 PM(UTC)
Alexander


Rank: Administration

Medals: Level 3: Shirt off your back! Received 25 Thanks!

Joined: 7/23/2013(UTC)
Posts: 715
Man
Location: Raleigh, NC

Was thanked: 66 time(s) in 63 post(s)
Hmm, if it's freezing your application, you could try using the asynchronous forms of GetRequestStream and GetResponse.
ScreenConnect Team
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.