Skip to main content
1-Visitor
July 31, 2016
Solved

Thingworx Service C# Call

  • July 31, 2016
  • 1 reply
  • 3238 views

Hi Everyone,

I am trying  to integrate thingworx into a .Net Web Application. I need to call a Tw Service but it does not work.The service returns an InfoTable

I enabled Allow Request Method Switch in Tw

Bellow is the code

var req = (HttpWebRequest)WebRequest.Create(url);

            req.Accept = "application/json";

            req.Method = "POST";

            req.ContentType = "application/json";

            req.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes("user:pass"));

       

            HttpWebResponse resp = req.GetResponse() as HttpWebResponse;

For the GET verb it works but it returns the service signature which is useless, but for POST it returns "The remote server returned an error: (400) Bad Request"

Dou you have any Samples of REST calls using C# ?

Thank you,

Tudor

Best answer by tbugnar

It is working.

It was a mistake in the service URL.

original

https://ptc-url/Thingworx/Things/MyThing/ServiceDefinitions/MyService

correct url

https://ptc-url/Thingworx/Things/MyThing/Services/MyService

1 reply

tbugnar1-VisitorAuthorAnswer
1-Visitor
July 31, 2016