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.
- Your server must have the current TLS and cipher suites.
- 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.
- Your server must allow connections from Power Platform and Dynamics 365 services IP address values specified under the AzureCloud service tag.
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
.GetAwaiter().GetResult() 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
In most cases outside of plug-ins, you will want to use
HttpClient. Within plug-ins, you can also use
WebClient if you prefer.
As called out in the following best practices topics:
- Set KeepAlive to false when interacting with external hosts in a plug-in
- Set Timeout when making external calls in a plug-in
You should make sure to set an appropriate
Timeout period for your external calls and disable
KeepAlive. See the above links for more information.