All Projects → watson-developer-cloud → Dotnet Standard Sdk

watson-developer-cloud / Dotnet Standard Sdk

Licence: apache-2.0
🆕🆕🆕.NET Standard library to access Watson Services.

Projects that are alternatives of or similar to Dotnet Standard Sdk

Statiq.framework
A flexible and extensible static content generation framework for .NET.
Stars: ✭ 251 (+74.31%)
Mutual labels:  hacktoberfest, dotnet-core
Practical Aspnetcore
Practical samples of ASP.NET Core 2.1, 2.2, 3.1, 5.0 and 6.0 projects you can use. Readme contains explanations on all projects.
Stars: ✭ 6,199 (+4204.86%)
Mutual labels:  hacktoberfest, dotnet-core
Fluentresults
A generalised Result object implementation for .NET/C#
Stars: ✭ 266 (+84.72%)
Mutual labels:  hacktoberfest, dotnet-core
Umbraco Cms
The simple, flexible and friendly ASP.NET CMS used by more than 730.000 websites
Stars: ✭ 3,484 (+2319.44%)
Mutual labels:  hacktoberfest, dotnet-core
Colore
A powerful C# library for Razer Chroma's SDK
Stars: ✭ 121 (-15.97%)
Mutual labels:  hacktoberfest, dotnet-core
Mond
A scripting language for .NET Core
Stars: ✭ 237 (+64.58%)
Mutual labels:  hacktoberfest, dotnet-core
Stryker Net
Mutation testing for .NET core and .NET framework!
Stars: ✭ 491 (+240.97%)
Mutual labels:  hacktoberfest, dotnet-core
Pixieditor
PixiEditor is a lightweight pixel art editor made with .NET 5
Stars: ✭ 210 (+45.83%)
Mutual labels:  hacktoberfest, dotnet-core
Azurestorageexplorer
☁💾 Manage your Azure Storage blobs, tables, queues and file shares from this simple and intuitive web application.
Stars: ✭ 88 (-38.89%)
Mutual labels:  hacktoberfest, dotnet-core
Fakeiteasy
The easy mocking library for .NET
Stars: ✭ 1,092 (+658.33%)
Mutual labels:  hacktoberfest, dotnet-core
Mysqlconnector
Async MySQL Connector for .NET and .NET Core
Stars: ✭ 942 (+554.17%)
Mutual labels:  hacktoberfest, dotnet-core
Wopihost
ASP.NET Core MVC implementation of the WOPI protocol. Enables integration with WOPI clients such as Office Online Server.
Stars: ✭ 132 (-8.33%)
Mutual labels:  hacktoberfest, dotnet-core
Rawcms
RawCMS is the headless CMS written in asp.net core build for developers that embraces API first technology. Please give us a feedback!
Stars: ✭ 132 (-8.33%)
Mutual labels:  hacktoberfest, dotnet-core
Coravel
Near-zero config .NET Core micro-framework that makes advanced application features like Task Scheduling, Caching, Queuing, Event Broadcasting, and more a breeze!
Stars: ✭ 1,989 (+1281.25%)
Mutual labels:  hacktoberfest, dotnet-core
Core Framework
This repository holds the Open RuneScape Classic game framework
Stars: ✭ 143 (-0.69%)
Mutual labels:  hacktoberfest
Practical Dapr
A full-stack .NET microservices build on Dapr and Tye
Stars: ✭ 140 (-2.78%)
Mutual labels:  dotnet-core
Shimmerswift
A swift implementation of Facebooks shimmer effect.
Stars: ✭ 143 (-0.69%)
Mutual labels:  hacktoberfest
Ultimate Java Resources
Java programming. All in one Java Resource for learning. Updated every day and up to date. All Algorithms and DS along with Development in Java. Beginner to Advanced. Join the Discord link.
Stars: ✭ 143 (-0.69%)
Mutual labels:  hacktoberfest
Slick
Static site generator built on Shake configured in Haskell
Stars: ✭ 144 (+0%)
Mutual labels:  hacktoberfest
Msbuild.sdk.sqlproj
An MSBuild SDK that provides similar functionality to SQL Server Data Tools (.sqlproj) projects
Stars: ✭ 142 (-1.39%)
Mutual labels:  hacktoberfest

Watson Developer Cloud .NET Standard SDK

Build status Coverage Status wdc-community.slack.com CLA assistant semantic-release Documentation

The .NET Standard SDK uses Watson services, a collection of REST APIs that use cognitive computing to solve complex problems.

Table of Contents

Announcements

Updating endpoint URLs from watsonplatform.net

Watson API endpoint URLs at watsonplatform.net are changing and will not work after 26 May 2021. Update your calls to use the newer endpoint URLs. For more information, see https://cloud.ibm.com/docs/watson?topic=watson-endpoint-change.

Personality Insights deprecation

IBM Watson™ Personality Insights is discontinued. For a period of one year from 1 December 2020, you will still be able to use Watson Personality Insights. However, as of 1 December 2021, the offering will no longer be available.

As an alternative, we encourage you to consider migrating to IBM Watson™ Natural Language Understanding, a service on IBM Cloud® that uses deep learning to extract data and insights from text such as keywords, categories, sentiment, emotion, and syntax to provide insights for your business or industry. For more information, see About Natural Language Understanding.

Visual Recognition deprecation

IBM Watson™ Visual Recognition is discontinued. Existing instances are supported until 1 December 2021, but as of 7 January 2021, you can't create instances. Any instance that is provisioned on 1 December 2021 will be deleted.

Compare and Comply deprecation

IBM Watson™ Compare and Comply is discontinued. Existing instances are supported until 30 November 2021, but as of 1 December 2020, you can't create instances. Any instance that exists on 30 November 2021 will be deleted. Consider migrating to Watson Discovery Premium on IBM Cloud for your Compare and Comply use cases. To start the migration process, visit https://ibm.biz/contact-wdc-premium.

Before you begin

Ensure you have the following prerequisites:

Installing the Watson .NET Standard SDK

This SDK provides classes and methods to access the following Watson services:

You can get the latest SDK packages through NuGet or manually here.

.NET Standard 2.0

The Watson .NET Standard SDK conforms to .NET Standard 2.0. It is implemented by .NET Core 2.0, .NET Framework 4.6.1 and Mono 5.4. See Microsoft documentation for details.

Authentication

Watson services are migrating to token-based Identity and Access Management (IAM) authentication.

  • With some service instances, you authenticate to the API by using IAM.
  • In other instances, you authenticate by providing the username and password for the service instance.
  • If you're using a Watson service on ICP, you'll need to authenticate in a specific way.

Getting credentials

To find out which authentication to use, view the service credentials. You find the service credentials for authentication the same way for all Watson services:

  1. Go to the IBM Cloud Dashboard page.
  2. Either click an existing Watson service instance or click Create resource > AI and create a service instance.
  3. Copy the url and either apikey or username and password. Click Show if the credentials are masked.

In your code, you can use these values in the service constructor or with a method call after instantiating your service.

IAM

Some services use token-based Identity and Access Management (IAM) authentication. IAM authentication uses a service API key to get an access token that is passed with the call. Access tokens are valid for approximately one hour and must be regenerated.

You supply either an IAM service API key or an access token:

  • Use the API key to have the SDK manage the lifecycle of the access token. The SDK requests an access token, ensures that the access token is valid, and refreshes it if necessary.
  • Use the access token if you want to manage the lifecycle yourself. For details, see Authenticating with IAM tokens. If you want to switch to API key override your stored IAM credentials with an IAM API key.

Supplying the IAM API key

void Example()
{
    IamAuthenticator authenticator = new IamAuthenticator(
        apikey: "{apikey}");
    var service = new AssistantService("{versionDate}", authenticator);
    service.SetServiceUrl("{serviceUrl}");
}

Supplying the access token

void Example()
{
    BearerTokenAuthenticator authenticator = new BearerTokenAuthenticator(
        bearerToken: "{bearerToken}");
    var service = new AssistantService("{versionDate}", authenticator);
    service.SetServiceUrl("{serviceUrl}");
}

Username and password

void Example()
{
    BasicAuthenticator authenticator = new BasicAuthenticator(
        username: "{username}",
        password: "{password}");
    var service = new AssistantService("{versionDate}", authenticator);
    service.SetServiceUrl("{serviceUrl}");
}

ICP

Like IAM, you can pass in credentials to let the SDK manage an access token for you or directly supply an access token to do it yourself.

Letting the SDK manage the token
void Example()
{
    CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator(
        url: "https://{cp4d_cluster_host}{:port}",
        username: "{username}",
        password: "{password}");
    var service = new AssistantService("{version-date}", authenticator);
    service.SetServiceUrl("{serviceUrl}");
    var results = service.Message("{workspace-id}", "{message-request}");
}
Managing the token yourself
void Example()
{
    BearerTokenAuthenticator authenticator = new BearerTokenAuthenticator(
        bearerToken: "{bearerToken}");
    var service = new AssistantService("{version-date}", authenticator);
    service.SetServiceUrl("{serviceUrl}");
    var results = service.Message("{workspace-id}", "{message-request}");
}

Be sure to both disable SSL verification when authenticating and set the endpoint explicitly to the URL given in ICP.

Supplying credentials

There are two ways to supply the credentials you found above to the SDK for authentication.

Credential file (easier!)

With a credential file, you just need to put the file in the right place and the SDK will do the work of parsing it and authenticating. You can get this file by clicking the Download button for the credentials in the Manage tab of your service instance.

The file downloaded will be called ibm-credentials.env. This is the name the SDK will search for and must be preserved unless you want to configure the file path (more on that later). The SDK will look for your ibm-credentials.env file in the following places (in order):

  • The top-level directory of the project you're using the SDK in
  • Your system's home directory

As long as you set that up correctly, you don't have to worry about setting any authentication options in your code. So, for example, if you created and downloaded the credential file for your Discovery instance, you just need to do the following:

AssistantService service = new AssistantService("{version-date}");
var listWorkspacesResult = service.ListWorkspaces();

And that's it!

If you're using more than one service at a time in your code and get two different ibm-credentials.env files, just put the contents together in one ibm-credentials.env file and the SDK will handle assigning credentials to their appropriate services.

If you would like to configure the location/name of your credential file, you can set an environment variable called IBM_CREDENTIALS_FILE. This will take precedence over the locations specified above. Here's how you can do that:

export IBM_CREDENTIALS_FILE="{path}"

where {path} is something like /home/user/Downloads/{file_name}.env.

Manually

If you'd prefer to set authentication values manually in your code, the SDK supports that as well. The way you'll do this depends on what type of credentials your service instance gives you.

Custom Request Headers

You can send custom request headers by adding them to the service using .WithHeader({key}, {value}).

void Example()
{
    IamAuthenticator authenticator = new IamAuthenticator(
        apikey: "{apikey}");
    var service = new AssistantService("{version-date}", authenticator);
    service.SetServiceUrl("{serviceUrl}");
    service.WithHeader("X-Watson-Metadata", "customer_id=some-assistant-customer-id");
    var results = service.Message("{workspace-id}", "{message-request}");
}

Response Headers, Status Code and Raw Json

You can get the response headers, status code and the raw json response in the result object.

void Example()
{
    IamAuthenticator authenticator = new IamAuthenticator(
        apikey: "{apikey}");
    var service = new AssistantService("{version-date}", authenticator);
    service.SetServiceUrl("{serviceUrl}");
    var results = service.Message("{workspace-id}", "{message-request}");
    
    var responseHeaders = results.Headers;  //  The response headers
    var responseJson = results.Response;    //  The raw response json
    var statusCode = results.StatusCode;    //  The response status code
}

Self signed certificates

You can disable SSL verification on calls to Watson (only do this if you really mean to!).

void Example()
{
    CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator(
        url: "https://{cp4d_cluster_host}{:port}",
        username: "{username}",
        password: "{password}",
        disableSslVerification: true);
    var service = new AssistantService("{version-date}", authenticator);
    service.SetServiceUrl("{serviceUrl}");
    var results = service.Message("{workspace-id}", "{message-request}");
}

Discovery V2

Discovery v2 is only available on Cloud Pak for Data.

Transaction IDs

Every SDK call returns a response with a transaction ID in the X-Global-Transaction-Id header. Together the service instance region, this ID helps support teams troubleshoot issues from relevant logs.

AssistantService service = new AssistantService("{version-date}");
DetailedResponse<WorkspaceCollection> listWorkspacesResult = null;

try
{
    listWorkspacesResult = service.ListWorkspaces();

    //  Global transaction id on successful api call
    listWorkspacesResult.Headers.TryGetValue("x-global-transaction-id", out object globalTransactionId);
}
catch(Exception e)
{
    //  Global transaction on failed api call is contained in the error message
    Console.WriteLine("error: " + e.Message);
}

However, the transaction ID isn't available when the API doesn't return a response for some reason. In that case, you can set your own transaction ID in the request. For example, replace <my-unique-transaction-id> in the following example with a unique transaction ID.

void Example()
{
    IamAuthenticator authenticator = new IamAuthenticator(
        apikey: "{apikey}");
    var service = new AssistantService("{version-date}", authenticator);
    service.SetServiceUrl("{serviceUrl}");
    service.WithHeader("X-Global-Transaction-Id", "<my-unique-transaction-id>");
    var results = service.Message("{workspace-id}", "{message-request}");
}

Use behind a proxy

To use the SDK behind an HTTP proxy, you need to set either the http_proxy or https_proxy environment variable. You can set this in the application environment using:

set http_proxy=http://proxy.server.com:3128

from the cmd.

You can also set this in the application using:

Environment.SetEnvironmentVariable("http_proxy", "http://proxy.server.com:3128");

Documentation

Click here for documentation by release and branch.

Questions

If you have issues with the APIs or have a question about the Watson services, see Stack Overflow.

Open Source @ IBM

Find more open source projects on the IBM Github Page.

License

This library is licensed under Apache 2.0. Full license text is available in LICENSE.

Contributing

See CONTRIBUTING.md.

Featured projects

We'd love to highlight cool open-source projects that use this SDK! If you'd like to get your project added to the list, feel free to make an issue linking us to it.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].