microsoft / PowerPlatform-DataverseServiceClient

Code Replica for Microsoft.PowerPlatform.Dataverse.Client and supporting nuget packages.
MIT License
285 stars 52 forks source link

Issue Accessing Organization Service #321

Closed DivyaYeddula closed 2 years ago

DivyaYeddula commented 2 years ago

{"An HttpListenerException occurred while listening on http://localhost:5017/login/ for the system browser to complete the login. Possible cause and mitigation: the app is unable to listen on the specified URL; run 'netsh http add iplisten 127.0.0.1' from the Admin command prompt."} InnerException {"The process cannot access the file because it is being used by another process."}
System.Exception {System.Net.HttpListenerException}

StackTrace "at Microsoft.PowerPlatform.Dataverse.Client.ConnectionService.d__187.MoveNext()" string

Message "Failed to connect to Dataverse"

StackTrace "at Microsoft.PowerPlatform.Dataverse.Client.ServiceClient.CreateServiceConnection(Object externalOrgServiceProxy, AuthenticationType requestedAuthType, String hostName, String port, String orgName, NetworkCredential credential, String userId, SecureString password, String domain, String Geo, String claimsHomeRealm, Boolean useSsl, Boolean useUniqueInstance, OrganizationDetail orgDetail, String clientId, Uri redirectUri, PromptBehavior promptBehavior, OrganizationWebProxyClientAsync externalOrgWebProxyClient, String certificateThumbPrint, StoreName certificateStoreName, X509Certificate2 certificate, Uri instanceUrl, Boolean isCloned, Boolean useDefaultCreds, Version incomingOrgVersion, ILogger externalLogger, String tokenCacheStorePath)\r\n at Microsoft.PowerPlatform.Dataverse.Client.ServiceClient.ConnectToService(String connectionString, ILogger logger)\r\n at ExPro.Provider.CRMServiceClient..ctor() in D:\Client-Stuff\Client\Mubadala\Mubadala.MazikCare.Clinical\ExPro Core\ExProModel.Model.Server\CRMServiceClient.cs:line 75"

EXCEPTION

In New version also i am facing same issue

version

new version exception

MattB-msft commented 2 years ago

@DivyaYeddula Need a bit more to work with here. Can you tell us the following: What sort of application is this ? (Windows client/Service/ API service / Function / etc. ) What sort of authentication are you using here? Are you using a connection string or one of the constructors? Can you provide us with a sanitized version of your connection code?

Also, the root error seems to be a file in use Error - "The Process cannot Access a file because its being used by another process", Did you provide a token cache file name and have that open in another tool?

thanks

DivyaYeddula commented 2 years ago

Hi Team,

We are using client side Blazor. Server side AspNetCore net6.0. Using Below connection sting and ServiceClient.

@.**@.;url=****;ClientId=****;ClientSecret=*****;RedirectUri=http://localhost:5017/login;loginPrompt=Auto

ServiceClient client = new ServiceClient(CRMConnectionString); ApplicationContext.ClientContext["OrganizationServiceProxy"] = client;

@.***

Here after 10-20 requests automatically giving the error, even passing the connection sting not able to create the instance of organization service client.

Thanks & Regards Divya.

From: MattB @.> Sent: 21 October 2022 21:35 To: microsoft/PowerPlatform-DataverseServiceClient @.> Cc: Yeddula Divya @.>; Mention @.> Subject: Re: [microsoft/PowerPlatform-DataverseServiceClient] Issue Accessing Organization Service (Issue #321)

@DivyaYeddulahttps://github.com/DivyaYeddula Need a bit more to work with here. Can you tell us the following: What sort of application is this ? (Windows client/Service/ API service / Function / etc. ) What sort of authentication are you using here? Are you using a connection string or one of the constructors? Can you provide us with a sanitized version of your connection code?

Also, the root error seems to be a file in use Error - "The Process cannot Access a file because its being used by another process", Did you provide a token cache file name and have that open in another tool?

thanks

— Reply to this email directly, view it on GitHubhttps://github.com/microsoft/PowerPlatform-DataverseServiceClient/issues/321#issuecomment-1287162817, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A3RVESVKIGME7K4645TZEPDWEK5LPANCNFSM6AAAAAARCJ2GMI. You are receiving this because you were mentioned.Message ID: @.**@.>>

petrochuk commented 2 years ago

Last time I tried using Dataverse Service client with WebAssembly a few months ago it was not supported. Server side Blazor should work though.

DivyaYeddula commented 2 years ago

Hi Team,

We are using ASPNET CORE net6.0 for server side, using Web API we are calling to server side.in this we are using Microsoft.PowerPlatform.Dataverse.Client DLL to connect the Dataverse. It is connecting to Dataverse up to 10-20 requests after that it is disconnecting.

At that time, we are getting Failed to connect to Dataverse exception.

We are connecting like this below

string CRMConnectionString = string.Format($@"AuthType=OAuth;Username={username};Password={password};url={URL};ClientId={appID};RedirectUri=http://localhost:5017/login;loginPrompt=Auto");

ServiceClient client = new ServiceClient(CRMConnectionString);

Thanks & Regards Divya.

From: Andrew Petrochuk @.> Sent: 26 October 2022 23:13 To: microsoft/PowerPlatform-DataverseServiceClient @.> Cc: Yeddula Divya @.>; Mention @.> Subject: Re: [microsoft/PowerPlatform-DataverseServiceClient] Issue Accessing Organization Service (Issue #321)

Last time I tried using Dataverse Service client with WebAssembly a few months ago it was not supported. Server side Blazor should work though.

— Reply to this email directly, view it on GitHubhttps://github.com/microsoft/PowerPlatform-DataverseServiceClient/issues/321#issuecomment-1292389740, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A3RVESUSF7UCQ3G6C6CEYWTWFFUQRANCNFSM6AAAAAARCJ2GMI. You are receiving this because you were mentioned.Message ID: @.**@.>>

MattB-msft commented 2 years ago

@DivyaYeddula a few things:

You're using a User / Password auth flow with LoginPrompt=Auto in a WebSite. Patten wise, this is going to get you into trouble as if MSAL, for any reason, decides that it needs user intervention your site is going to hang as its going to try to pop a user dialog for action. -

This IS the error you're seeing above. MSAL is trying to pop a user dialog.

If what your trying to do is capture the user ID of the user connecting to the website and use that as the user to connect to dataverse, you would need to manage auth on your own (not use the onboard system) and do a token exchange / On Behalf of authentication flow.

If you're trying to get the website an identity to talk to dataverse with, then you should use an App Identity instead of a user identity. You can use a Client Secret flow, or a Client Certificate flow for this.

Also are you creating a new connection (calling new ServiceClient(...) ) on each action from the page? If so I would suggest that you create a copy of the connection your going to use during startup and only recycle that if the connection fails.

Thanks

MattB-msft commented 2 years ago

@DivyaYeddula Im going to close this issue, assuming that your going to shift over to using App Identities. if your still having issues, please feel free to reopen it or create a new Issue.