Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 general forum

How to specify proxy details when calling to dynamics CRM Web Service from Console Application

(0) ShareShare
ReportReport
Posted on by

Hello All, I am new to Dynamics CRM web services, I want to consume web service from a console application, it's working from my local but when it goes to production server it's not working as the production server requires a proxy to set up before calling the web service. Can somebody explain how to use a proxy before calling the web service, this is the code which is working in my local machine over the internet

private static void ConnectToDynamics()
    {
        string odataUrl = _dynamicsURL; 
        string appId = Id;
        string clientSecret = _secret;

        AuthenticationParameters authArg = AuthenticationParameters.CreateFromResourceUrlAsync(new Uri(odataUrl)).Result;
        AuthenticationContext authCtx = new AuthenticationContext(authArg.Authority);
        AuthenticationResult authRes = authCtx.AcquireTokenAsync(authArg.Resource, new ClientCredential(appId, clientSecret)).Result;

        using (OrganizationWebProxyClient webProxyClient = new OrganizationWebProxyClient(new Uri(odataUrl), false))
        {
            webProxyClient.HeaderToken = authRes.AccessToken;
            using (OrganizationServiceContext ctx = new OrganizationServiceContext((IOrganizationService)webProxyClient))
            {

                var accounts = (from i in ctx.CreateQuery("entity") orderby i["name"] select i).Take(100);
                foreach (var account in accounts)
                    Console.WriteLine(account["name"]);
            }
        }
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Dynamics 365 general forum

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans