microsoft / PowerPlatform-DataverseServiceClient

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

ServiceClient Connection get 401 exception during the WCF Service #283

Closed edmundtse49 closed 2 years ago

edmundtse49 commented 2 years ago

Hello, I have a custom webapi to use the SDK of Dataverse ServiceClient to connect CDS. The connection is success. However, after I turn on the App Insights, I find that the 401 exception is given out during the WCF Service.

image

Information for hosting setup: Host OS: Linux in the AKS SDK: Microsoft.PowerPlatform.Dataverse.Client (0.5.10) Framework: .NET 5.0

Connection string and ServiceClient:

    private void Connect(string AuthType, string InstanceURL, string ClientId, string ClientSecret)

{ string sConnectionStr = string.Format("AuthType={0};url={1};ClientId={2};ClientSecret={3};", AuthType, InstanceURL, ClientId, ClientSecret); Connect(sConnectionStr); }

    private void Connect(string ConnectionStr)
    {
        try
        {
            _svc = new ServiceClient(ConnectionStr);
            _svc.EnableAffinityCookie = false;
            if (_svc.IsReady)
            {
                Service = (IOrganizationService)_svc;
                Console.WriteLine("Connection Established Successfully...");
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }

    public void Disconnect()
    {
        _svc.Dispose();
    }

May I know that the 401 exception is expected or not? If not, could you provide any suggestion to solve this 401 exception?

Thanks a lot!

MattB-msft commented 2 years ago

This is expected, it is part of the authentication sequence that deals with discovery of the correct authority and tenant information for login.


From: Edmund Tse @.> Sent: Friday, June 10, 2022 2:13:50 AM To: microsoft/PowerPlatform-DataverseServiceClient @.> Cc: Subscribed @.***> Subject: [microsoft/PowerPlatform-DataverseServiceClient] ServiceClient Connection get 401 exception during the WCF Service (Issue #283)

Hello, I have a custom webapi to use the SDK of Dataverse ServiceClient to connect CDS. The connection is success. However, after I turn on the App Insights, I find that the 401 exception is given out during the WCF Service.

[image]https://user-images.githubusercontent.com/44049506/173031849-76826322-9c36-4580-b16c-25f6ccd0b5a0.png

Information for hosting setup: Host OS: Linux in the AKS SDK: Microsoft.PowerPlatform.Dataverse.Client (0.5.10) Framework: .NET 5.0

Connection string and ServiceClient: ` private void Connect(string AuthType, string InstanceURL, string ClientId, string ClientSecret) { string sConnectionStr = string.Format("AuthType={0};url={1};ClientId={2};ClientSecret={3};", AuthType, InstanceURL, ClientId, ClientSecret); Connect(sConnectionStr); }

private void Connect(string ConnectionStr)
{
    try
    {
        _svc = new ServiceClient(ConnectionStr);
        _svc.EnableAffinityCookie = false;
        if (_svc.IsReady)
        {
            Service = (IOrganizationService)_svc;
            Console.WriteLine("Connection Established Successfully...");
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
}

public void Disconnect()
{
    _svc.Dispose();
}

`

May I know that the 401 exception is expected or not? If not, could you provide any suggestion to solve this 401 exception?

Thanks a lot!

— Reply to this email directly, view it on GitHubhttps://github.com/microsoft/PowerPlatform-DataverseServiceClient/issues/283, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACQUENCZ6N6GRPJPBX3255TVOMBM5ANCNFSM5YNAC6IQ. You are receiving this because you are subscribed to this thread.Message ID: @.***>

edmundtse49 commented 2 years ago

@MattB-msft , thank you for your information. That means that I do not need to solve this, right?

MattB-msft commented 2 years ago

Correct


From: Edmund Tse @.> Sent: Friday, June 10, 2022 8:56:13 PM To: microsoft/PowerPlatform-DataverseServiceClient @.> Cc: MattB @.>; Mention @.> Subject: Re: [microsoft/PowerPlatform-DataverseServiceClient] ServiceClient Connection get 401 exception during the WCF Service (Issue #283)

@MattB-msfthttps://github.com/MattB-msft , thank you for your information. That means that I do not need to solve this, right?

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