I am trying to get an access token using Forge DA using the code below. But it throws the following exception:
An exception of type 'Autodesk.Forge.Client.ApiException' occurred in mscorlib.dll but was not handled in user code. Additional information: Error calling Authenticate: The underlying connection was closed: An unexpected error occurred on a send.
Here is my code:
TwoLeggedApi oAuth = new TwoLeggedApi();
dynamic token = await oAuth.AuthenticateAsync(
txtClientId.Text,
txtClientSecret.Text,
oAuthConstants.CLIENT_CREDENTIALS ,
new Scope[] { Scope.BucketRead, Scope.BucketCreate, Scope.DataRead, Scope.DataWrite });
Since the error is calling out connection make sure your system can reach our service from your network (check proxy, firewall etc, can you reach our other endpoints?) and it supports TLS 1.2 - see here
I recommend that you use the Design Automation SDK here. This one allows you to access the new V3 API while the one I presume you are using can only access the now deprecated V2 API.
Here's a sample that uses this SDK.
Related
I'm trying to connect to a remote Dynamics CRM instance and getting this exception on the ServiceClient constructor:
Failed to connect to Dataverse
Inner Exception 1: One or more errors occurred.
Inner exception 2: Need a non-empty authority
Parameter name: Authority
Key here is that it works fine from my dev machine--the error only occurs when I move the code to another server.
Here's the code:
string crmConnectionString =
$"AuthType=OAuth;Username=user#contoso.com;Password=whatever;Url=my-app.crm.dynamics.com;LoginPrompt=Never";
using (ServiceClient service = new ServiceClient(crmConnectionString)) // throws here
I used Wireshark to sniff the data and noticed the working server is sending the client hello using TLS v1.2, whereas the failing server is sending a slightly shorter (fewer bytes) hello using TLS v1. Could the issue be related to this and, if so, how do I fix it?
I have confirmed that TLS 1.2 is indeed required when communicating with online Dynamics 365. The solution in my case was to add this line directly above the constructor:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
This forces the protocol to TLS 1.2 and allows the code to work on both servers.
Note that there are probably better ways to solve this, such as upgrading your OS to get the newer TLS. That way your code won't be stuck on TLS 1.2 when newer versions become available. But the code addition is a potentially quick way forward for those who need it.
More info here and here.
Here is my code:
string url = "https://myOrg.api.crm.dynamics.com";
string apiVersion = "9.1";
string webApiUrl = $"{url}/api/data/v{apiVersion}/";
var authParameters = AuthenticationParameters.CreateFromResourceUrlAsync(new Uri(webApiUrl)).Result;
My last line of code is failing with:
The ouput is:
MyAPITest.vshost.exe Error: 0 : 11/05/2019 19:20:17: - AuthenticationParameters: System.ArgumentException: Unauthorized Http Status Code (401) was expected in the response
Parameter name: response
Exception thrown: 'System.AggregateException' in mscorlib.dll
The program '[5556] MyAPITest.vshost.exe' has exited with code -1 (0xffffffff).
For reference, I am attempting to use the Quick Start Guide to connect to the Common Data Service.
EDIT:
In looking at the details I am seeing:
Error
The underlying connection was closed: An unexpected error occured on a send.
More detail beneath that error:
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
AuthenticationParameters: System.ArgumentException: Unauthorized Http Status Code (401) was expected in the response
The error is typically because it's lacking valid authentication credentials and the request has not been applied for the target resource.
Also if you don't know, the AuthenticationParameters.CreateFromResourceUrlAsync API is obsolete, read more there.
With this in mind, I would look into using AuthenticationParameters.CreateFromUrlAsync(Uri) Method in which should be used. It sends a GET request to the url provided with no Authenticate header. If a 401 Unauthorized is received, this helper will parse the WWW-Authenticate header to retrieve the authority and resource.
Here was the problem, found in the guide:
I am running VS 2015. Once I unchecked this, it worked perfectly.
I am working on Xamarin Forms to create a native application. I am new to Xamarin and as well as google cloud vision API. I am trying to create ImageAnnotatorClient object (client) by passing it channel as parameter to the Create() method. However, it doesn't create the client and gives this exception.
Exception:
Unhandled Exception:
System.TypeInitializationException: The type initializer for 'Microsoft.Extensions.PlatformAbstractions.PlatformServices' threw an exception.
Code:
So, could be a problem of passing the JSON file incorrectly? I am not sure if I am doing it correctly. If it is not that could any please help me figure out how to resolve this exception?
Any help will be highly appreciated.
Thanks,
Ghalib
I have followed this tutorial to update a powerbi dashboard here.
I have copied all the code from Microsoft's website. Of course I have supplied my own clientId.
The console application successfully creates a dataset, but does not add rows to the table.
It fails here:
var response = (HttpWebResponse)request.GetResponse();
An unhandled exception of type 'System.Net.WebException' occurred in System.dll
Additional information: The remote server returned an error: (404) Not Found.
The URL you are querying is wrong or no longer exists. Check the documentation for the APIs you are querying to make sure you are properly constructing the URL.
Start here for PowerBI APIs: https://msdn.microsoft.com/library/dn877544.aspx
I am developing Application for Windows Phone using .Net Compact Framework 3.5
I am trying to connect Web Services from this application.
It is not connecting it in First Attempt, but it is connecting successfully in second and further attempts.
In First Attempt, It is giving "Web Exception" Error.
I am using following code for connecting:
SalesService.SalesService obj = new SalesService.SalesService();
string s = obj.CheckForValidService();
It is giving error in CheckForValidService method from Reference.cs file.
Ah, the old Expect-100 header issue. You will need to surpress the use of that header.
System.Net.ServicePointManager.Expect100Continue = false;
MSDN details:
http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.expect100continue(v=vs.90).aspx
Stackoverflow details:
The request failed with HTTP status 417: Expectation Failed - Using Web Services