1 Reply Latest reply on Sep 3, 2015 4:37 AM by miikkae RSS
    miikkae Explorer

    Unable to connect with .NET SDK to Thingworx

    I've been developing a .NET SDK test case for a while and everything went smoothly a couple weeks back.

    Now I tried adding setAvatar service call to set some randomly generated bitmap as avatar for the thing and it isn't connecting anymore.

    I tried taking every new additions out from the code and still it ain't connecting. I can't see anything connecting from Thingworx side logs (no access to the server logs, though).

     

    I've checked that all my properties (FieldDefinitions) in the datashape are correct and so forth. After start() method it !isShutdown() and !isConnected().

     

    I'm pretty new to C# overall, tried to run analysis, add debug messages etc to the code but got no clue where's this going wrong.

    Any idea where/how I could try to find the error?

    This is the first test case I've tried with so I have no other code to test if the connection overall is working.

    Haven't tested the original test code for at least a week so there might've happened something weird with connections too.

    At least basic websocket echo test connects to that url.

     

    EDIT: Just to clarify, it's the ConnectedThingClient (or its subclasses) object that won't connect.
    Tried also BaseClient.checkConnection method after start (and also connect method between them) but it just seems to throw a ConnectionException with no further details.

     

    I'm starting to feel miserable and frustated. I can get websocket open with simple js calls, C SDK code etc. but not with .NET SDK. There's nothing even in the Communication logs while I run this.

     

    Here's my current Client code. I even took off the things just to see if the client itself connects but it doesn't.

    If args.Length is under two, it defines the correct values for now, to test this (changed for this code). Also, I've tried with and without the setName and setAsSDKType methods but neither works.

     

    The result here is looping text "Client not connected"

     

    Any ideas? The C SDK works with the same ThingTemplate, ThingShape, etc and appKey is the same. The url there's my.server.tld while the TLS-configuration is set otherwise as is the path /Thingworx/WS.

     

    This whole code is made based on SteamSensorClient and SteamThing samples gotten from .NET SDK. In MyThing just some parameters's parsed off and names changed but mainly it's the same.

     

    namespace MySimpleTestClient  
    {  
        public class MyThingClient : ConnectedThingClient  
        {  
            public MyThingClient(ClientConfigurator config) : base(config) {}  
      
            public static void Main(string[] args)  
            {  
                if (args.Length < 2)  
                {  
                    args = new string[] { "wss://my.server.tld/Thingworx/WS", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "1000" };  
                }  
                ClientConfigurator config = new ClientConfigurator();  
                config.setUri(args[0]);  
                config.setReconnectInterval(5);  
                config.setSecurityClaims(SecurityClaims.fromAppKey(args[1].Trim()));  
                int scanRate=(args.Length>2?Int32.Parse(args[2]):1000);  
                     
                config.setName("MyGateway");  
                config.setAsSDKType();  
      
                MyThingClient client = new MyThingClient(config);  
                //MyThing mt1 = new MyThing("MyThing1", "My first Thing", client);  
                //client.bindThing(mt1);  
                try  
                {  
                    client.start();  
                }  
                catch (Exception eStart)  
                {  
                    Console.WriteLine("Initial Start Failed due to " + eStart.GetType() + " : " + eStart.Message);  
                    Console.WriteLine(eStart.StackTrace);  
                }  
      
                while (!client.isShutdown())  
                {  
                    if (client.isConnected())  
                    {  
                        foreach (VirtualThing thing in client.getThings().Values)  
                        {  
                            try  
                            {  
                                thing.processScanRequest();  
                            }  
                            catch (Exception eProcessing)  
                            {  
                                Console.WriteLine(eProcessing.GetType() + ": Error Processing Scan Request for [" + thing.getName() + "] : " + eProcessing.Message);  
                                Console.WriteLine(eProcessing.StackTrace);  
                            }  
                        }  
                    }  
                    else  
                    {  
                        Console.WriteLine("Client not connected!"); 
                    }
                    Thread.Sleep(scanRate);
                }
            }
        }
    }