Robert Thompson
Robert Thompson

Reputation: 67

OrganizationWebProxyClient - Endpoint = Address=error CS0103: The name '_address' does not exist in the current context, ClientCredentials

I am using OrganizationWebProxyClient to access organization service for CRM. I am getting an error message that does not make any sense.

I have nothing in my code that has to do with "_address". I thought the error message was referring to my URL.

Endpoint = Address=error CS0103: The name '_address' does not exist in the current context, ClientCredentials = {System.ServiceModel.Description.ClientCredentials}

        var clientId = "YOUR_CLIENT_ID";
        var clientSecret = "YOUR_CLIENT_SECRET";
        var organizationUrl = "YOUR_ORGANIZATION_URL";
        var tenantId = "YOUR_TENANT_ID";

        //this specific scope means that application will default to what is defined in the application registration rather than using dynamic scopes
        List<string> scopes = new List<string>();
        scopes.Add("https://graph.microsoft.com/.default");

        var cca = ConfidentialClientApplicationBuilder.Create(clientId)
                                          .WithAuthority(authority)
                                          .WithRedirectUri(organizationUrl)
                                          .WithClientSecret(clientSecret)
                                          .Build();

        // Retrieve an access token for Microsoft Graph (gets a fresh token if needed).
        var authResult = cca
             .AcquireTokenForClient(scopes)
             .ExecuteAsync();

        var tokenKey = authResult.Result.AccessToken;

        OrganizationWebProxyClient sdkService = null;
        try
        {
            //ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            sdkService = new OrganizationWebProxyClient(GetServiceUrl(organizationUrl), new TimeSpan(0, 10, 0), false);

            sdkService.HeaderToken = tokenKey;
        }
        catch (Exception ex)
        {
            log.LogInformation("There is issue while generating the token " + ex.Message);
        }

        return sdkService

enter image description here

Upvotes: 2

Views: 3464

Answers (2)

Dar&#237;o Le&#243;n
Dar&#237;o Le&#243;n

Reputation: 700

While debbuging, if I inspect the client ("sdkService") properties' values before the call to an operation contract (web method), it turns the client into a faulted state, and then the call will fail.

So you can't inspect client properties before any web service call.

Upvotes: 4

Red Hodgerson
Red Hodgerson

Reputation: 11

You'll see this error when attempting to use the current CRM/CDS/DV SDK with .NET Core versus .NET Framework as it's not compatible. Use Framework or use the Alpha version of the SDK from https://github.com/microsoft/PowerPlatform-CdsServiceClient which is compatible with Core.

Upvotes: 0

Related Questions