cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

Unable to connect with .NET SDK to Thingworx

miikkae
1-Newbie

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.

  1. namespace MySimpleTestClient 
  2.     public class MyThingClient : ConnectedThingClient 
  3.     { 
  4.         public MyThingClient(ClientConfigurator config) : base(config) {} 
  5.  
  6.         public static void Main(string[] args) 
  7.         { 
  8.             if (args.Length < 2
  9.             { 
  10.                 args = new string[] { "wss://my.server.tld/Thingworx/WS", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "1000" }; 
  11.             } 
  12.             ClientConfigurator config = new ClientConfigurator(); 
  13.             config.setUri(args[0]); 
  14.             config.setReconnectInterval(5); 
  15.             config.setSecurityClaims(SecurityClaims.fromAppKey(args[1].Trim())); 
  16.             int scanRate=(args.Length>2?Int32.Parse(args[2]):1000); 
  17.                 
  18.             config.setName("MyGateway"); 
  19.             config.setAsSDKType(); 
  20.  
  21.             MyThingClient client = new MyThingClient(config); 
  22.             //MyThing mt1 = new MyThing("MyThing1", "My first Thing", client); 
  23.             //client.bindThing(mt1); 
  24.             try 
  25.             { 
  26.                 client.start(); 
  27.             } 
  28.             catch (Exception eStart) 
  29.             { 
  30.                 Console.WriteLine("Initial Start Failed due to " + eStart.GetType() + " : " + eStart.Message); 
  31.                 Console.WriteLine(eStart.StackTrace); 
  32.             } 
  33.  
  34.             while (!client.isShutdown()) 
  35.             { 
  36.                 if (client.isConnected()) 
  37.                 { 
  38.                     foreach (VirtualThing thing in client.getThings().Values) 
  39.                     { 
  40.                         try 
  41.                         { 
  42.                             thing.processScanRequest(); 
  43.                         } 
  44.                         catch (Exception eProcessing) 
  45.                         { 
  46.                             Console.WriteLine(eProcessing.GetType() + ": Error Processing Scan Request for [" + thing.getName() + "] : " + eProcessing.Message); 
  47.                             Console.WriteLine(eProcessing.StackTrace); 
  48.                         } 
  49.                     } 
  50.                 } 
  51.                 else 
  52.                 { 
  53.                     Console.WriteLine("Client not connected!");
  54.                 }
  55.                 Thread.Sleep(scanRate);
  56.             }
  57.         }
  58.     }
  59. }

1 ACCEPTED SOLUTION

Accepted Solutions

Seems like the problem was with self-signed certificates.

I had .NET SDK 5.1 and after updating to 5.5 added config.AllowSelfSignedCertificates = true; and it started working.

View solution in original post

1 REPLY 1

Seems like the problem was with self-signed certificates.

I had .NET SDK 5.1 and after updating to 5.5 added config.AllowSelfSignedCertificates = true; and it started working.

Top Tags