Access external web services

Plug-ins and custom workflow activities can access the network through the HTTP and HTTPS protocols. This capability provides support for accessing popular web services like social sites, news feeds, web services, and more. The following web access restrictions apply to this sandbox capability.

  • Only the HTTP and HTTPS protocols are allowed.
  • Access to localhost (loopback) is not permitted.
  • IP addresses cannot be used. You must use a named web address that requires DNS name resolution.
  • Anonymous authentication is supported and recommended. There is no provision for prompting the logged on user for credentials or saving those credentials.

Other methods of accessing web services include the use of webhooks and the Azure Service Bus. Refer to the links provided below for more information on those topics.

How to access external web services

Today most people are familiar with the System.Net.Http.HttpClient Class. HttpClient was introduced with .NET 4.5 and provides significant capabilities over the System.Net.WebClient Class which is still available.

For new plug-ins you should use HttpClient because the .NET team doesn't recommend WebClient for new development. However, this doesn't mean you must replace any legacy code uses of WebClient that you find. Most of the advantages provided in HttpClient do not necessarily provide advantages within a plug-in. HttpClient is intended to be re-used and is asynchronous by default. Unless you are making multiple Http requests within your plug-in, WebClient is designed for a single request. Because HttpClient is asynchronous by default, you need to break away from typical use patterns and add code to force the operations to be performed synchronously, typically by removing the await keyword and appending .Result to any asynchronous calls.

WebClient provides simple synchronous methods such as UploadData, DownloadFile which don't clearly expose the underlying Http method used, but they can be set using specific overrides such as UploadString(String, String, String) in case you want to use PATCH instead of POST.

In most cases outside of plug-ins, you will want to use HttpClient. Within plug-ins, you can also use WebClient if you prefer.

Best practices

As called out in the following best practices topics:

You should make sure to set an appropriate Timeout period for your external calls and disable KeepAlive. See these topics for more information.

See also

Plug-ins
Workflow extensions
Azure integration
Use Web Hooks
Sample: Web Access from a Sandboxed Plug-in