Help
  • Explore Community
  • Get Started
  • Ask the Community
  • How-To & Best Practices
  • Contact Support
Notifications
Login / Register
Community
Community
Notifications
close
  • Forums
  • Knowledge Center
  • Events & Webinars
  • Ideas
  • Blogs
Help
Help
  • Explore Community
  • Get Started
  • Ask the Community
  • How-To & Best Practices
  • Contact Support
Login / Register
Sustainability
Sustainability

We Value Your Feedback!
Could you please spare a few minutes to share your thoughts on Cloud Connected vs On-Premise Services. Your feedback can help us shape the future of services.
Learn more about the survey or Click here to Launch the survey
Schneider Electric Services Innovation Team!

Generate client in Visual Studio for SmartConnector RESTful Endpoints

SmartConnector Forum

Schneider Electric support forum about SmartConnector applications for integration of other building management systems (BMS) into EcoStruxure Building Operation.

cancel
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Home
  • Schneider Electric Community
  • EcoStruxure Building
  • SmartConnector
  • SmartConnector Forum
  • Generate client in Visual Studio for SmartConnector RESTful Endpoints
Options
  • Mark Topic as New
  • Mark Topic as Read
  • Float this Topic for Current User
  • Bookmark
  • Subscribe
  • Mute
  • Printer Friendly Page
Invite a Co-worker
Send a co-worker an invite to the portal.Just enter their email address and we'll connect them to register. After joining, they will belong to the same company.
You have entered an invalid email address. Please re-enter the email address.
This co-worker has already been invited to the Exchange portal. Please invite another co-worker.
Please enter email address
Send Invite Cancel
Invitation Sent
Your invitation was sent.Thanks for sharing Exchange with your co-worker.
Send New Invite Close
Top Experts
User Count
JeffBowman
Sisko JeffBowman Sisko
164
ardak
ardak Schneider Alumni (Retired)
34
sesa180908_brid
Commander sesa180908_brid Commander
34
mike_meirovitz
Commander mike_meirovitz
21
View All

Invite a Colleague

Found this content useful? Share it with a Colleague!

Invite a Colleague Invite
Back to SmartConnector Forum
JeffBowman
Sisko JeffBowman Sisko
Sisko

Posted: ‎2017-02-02 07:31 AM

6 Likes
9
1433
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2017-02-02 07:31 AM

Generate client in Visual Studio for SmartConnector RESTful Endpoints

When consuming the SmartConnector RESTful Endpoints, it is always necessary (or at least incredibly helpful and time saving) to have a Client. Luckily because SmartConnector REST leverages swagger, these clients can be autogenerated for you! This generated client contains all the interfaces and classes needed to extend it as well as all the Models needs to send requests, and receive deserialized responses.

Follow the steps below:

1. Navigate to your swagger page and then copy and paste the URL that contains the actually swagger DOC should look something like: "http://10.169.86.198:8083/SBO/swagger/docs/v1

2. Go to file >>save, and save as a .json file

3. In Visual studio, in your project go to Add >REST Api Client. Select the "Select an existing Swagger metadata file" and browse to your file and select OK. If you do not see this option, make sure you have installed the Azure SDK on your VS installation.

4. You should see a new Folder in your project that contains all the interfaces and classes needed to use this client. The client class name should be the name of your Endpoint (in my case it is SboRestEndpoint).

The ONLY thing that this autogenerated client does NOT have, is the ability to get a BearerToken(for some reason this endpoint isn't exposed from Swagger) but this can be done pretty simply using the BeaerToken class in Mongoose.Common.Security, see below:

var token = BearerToken.ObtainToken(BaseUri, Username, Password, "GetToken");

5. Initialize your client. An example on how to initialize your client is seen below:

            var token = BearerToken.ObtainToken(baseUri, username, password, "GetToken");

            var credentials = new TokenCredentials(null, token.access_token);

            var client = new SBORestEndpoint {Credentials = credentials, BaseUri = baseUri};

            client.Credentials?.InitializeServiceClient(client);

6. Use your client (examples below)

            var rootResponse = client.Root.RetrieveWithOperationResponseAsync();

            var sboEwsId = "01/Server 1/MyValueItem";

            var valueResponse = client.Values.RetrieveByIdWithOperationResponseAsync(sboEwsId.UrlEncodeToString());

One helpful thing to note is that certain requests, the ones that you can add custom string in a URL (generally the {id} in the request URLs), those parameters need to be DOUBLE encoded for some reason (the autogenerated client, single encodes by default).. I wrote an extension method for this (see below, you will notice it was used above):

        #region UrlEncodeToString

        public static string UrlEncodeToString(this string stringToEncode)

        {

            if(string.IsNullOrEmpty(stringToEncode))

            {

                return null;

            }

            else

            {

                return HttpUtility.UrlEncode(stringToEncode.Replace(" ", "~")).Replace("%7e", " ");

            }

        }

        #endregion

If you need anymore examples using the AutoGenerated client, please let me know.

Also, if interested in using a different programming language for the client, the same program that Visual Studio uses to create the Client, can be used as a command line tool to create clients in other languages, see link: GitHub - Azure/autorest: Swagger (OpenAPI) Specification code generator featuring C# and Razor templ...

-Jeff

Reply
  • All forum topics
  • Previous Topic
  • Next Topic
Replies 9
JeffBowman
Sisko JeffBowman Sisko
Sisko

Posted: ‎2017-02-02 07:55 AM

0 Likes
0
1147
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2017-02-02 07:55 AM

NOTE: There is a current bug when using the BearerToken.ObtainToken() method. It only works with the username 'admin'. A patch for this will be released along with the 'offical' documentation. If you need the fixes sooner than that, we can post to the CTP feed. Just let us know!

As of SmartConnector 2.2.124 (now up on SmartConnectorServer), this issue has been resolved!

Reply
SteveGregory
Commander SteveGregory Commander
Commander

Posted: ‎2017-03-15 03:03 PM

0 Likes
5
1148
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2017-03-15 03:03 PM

Hi Jeffrey, this is really helpful. Is this information available as a document that we can issue to third party developers?

Reply
sesa180908_brid
Commander sesa180908_brid Commander
Commander

Posted: ‎2017-03-15 03:24 PM

0 Likes
4
1148
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2017-03-15 03:24 PM

Steve,

There really is no notion of "third party developer", there is only a registered SmartConnector Developer.  All known issues are published with each release and are available to all SmartConnector Developers.

As issues are discovered between releases, we will update the last version of the release notes accordingly.

Reply
SteveGregory
Commander SteveGregory Commander
Commander

Posted: ‎2017-03-15 03:37 PM

0 Likes
3
1148
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2017-03-15 03:37 PM

Sorry my reply was intended for initial post, and the comment was around having a similar one page 'cheat sheet' on how to quickly integrate to our SmartConnector, that we can give to third party developers. 

Reply
JeffBowman
Sisko JeffBowman Sisko
Sisko

Posted: ‎2017-03-16 09:35 AM

0 Likes
1
1148
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2017-03-16 09:35 AM

Hi Steven,

We have no official documentation for this except for this post. But in theory, we could create a PDF from it if that works, or you could just copy it if you wanted as well.

An issue that you would most likely encounter for a third party (non SmartConnector developer) is that they won't have access to the BearerToken.ObtainToken() method, as they won't have access to the SmartConnector Nuget packages. So they would need to write their own method for this.

Basically they will need to post to the Token endpoint with a body like the below.

grant_type=password&username=myusername&password=mypassword

We are most likely going to abstract out this method, so that anyone can use it. But for now, they will need to roll their own.

Regards,

-Jeff

Reply
sesa180908_brid
Commander sesa180908_brid Commander
Commander

Posted: ‎2017-03-16 09:41 AM

0 Likes
0
1148
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2017-03-16 09:41 AM

Steve,

We'll look into providing some public facing artifacts, be it just documentation or perhaps a public NuGet which already has the proxy classes. 

Reply
sesa180908_brid
Commander sesa180908_brid Commander
Commander

Posted: ‎2017-03-19 03:50 PM

2 Likes
0
1148
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2017-03-19 03:50 PM

Steve,

I updated the samples repo on GitHub to include a REST client based on Jeff's original post.  See GitHub - BuildingsLabs/SmartConnectorSamples: Sample projects for SmartConnector It has some additional feautres around re-authenticating if the token has expired and so on.  Since this is public, it can be shared with outside consumers.

We'll probably add more over time, but it is certainly a good place to start.

Reply
sesa237670_brid
sesa237670_brid Schneider Alumni (Retired)
Schneider Alumni (Retired)

Posted: ‎2018-02-12 08:02 AM

0 Likes
1
1148
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2018-02-12 08:02 AM

"In Visual studio, in your project go to Add >REST Api Client. Select the "Select an existing Swagger metadata file" and browse to your file and select OK."

Does this work with Visual Studio 2017 ? I am using VS2015 and don't see the option to add Rest Api client in my project.

Reply
JeffBowman
Sisko JeffBowman Sisko
Sisko

Posted: ‎2018-02-12 08:37 AM

0 Likes
0
1147
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2018-02-12 08:37 AM

Hi Neeraj,

I am not 100% sure if it is in VS2015 or not, but i definitely recommend updating to VS2017.

That said, the application used for creating the client 'AutoRest' is actually a command line tool, so you can actually just do it manually. See the link in the blog post for more information about that.

Regards,

-Jeff

Reply
Preview Exit Preview

never-displayed

You must be signed in to add attachments

never-displayed

 
To The Top!

Forums

  • APC UPS Data Center Backup Solutions
  • EcoStruxure IT
  • EcoStruxure Geo SCADA Expert
  • Metering & Power Quality
  • Schneider Electric Wiser

Knowledge Center

Events & webinars

Ideas

Blogs

Get Started

  • Ask the Community
  • Community Guidelines
  • Community User Guide
  • How-To & Best Practice
  • Experts Leaderboard
  • Contact Support
Brand-Logo
Subscribing is a smart move!
You can subscribe to this board after you log in or create your free account.
Forum-Icon

Create your free account or log in to subscribe to the board - and gain access to more than 10,000+ support articles along with insights from experts and peers.

Register today for FREE

Register Now

Already have an account? Login

Terms & Conditions Privacy Notice Change your Cookie Settings © 2025 Schneider Electric

This is a heading

With achievable small steps, users progress and continually feel satisfaction in task accomplishment.

Usetiful Onboarding Checklist remembers the progress of every user, allowing them to take bite-sized journeys and continue where they left.

of