Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

azure functions, hybrid connection communicate with Dynamics crm 8.2 (onPrem) Issue: unable to connect to the remote server -> An attempt was made to access a socket in a way forbidden by its access permissions 127.0.0.5:44

Posted on by 547

Error: "message": "Exception while executing function: Function1 -> Metadata contains a reference that cannot be resolved: 'crm.xyz.com/.../Organization.svc. -> Unable to connect to the remote server -> An attempt was made to access a socket in a way forbidden by its access permissions 127.0.0.5:443

Things performed till now

  1. After lot of research I was successful to make hybrid connection from Azure cloud to OnPrem CRM Server (with correct port name and port address
  2. This is showing as connected both on server and on Azure
  3. To simply test I did telnet on CMD (kunudu) and I was successful
  4. I wrote few lines of code to have orgservice with username and password. This was successful.

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
IServiceManagement orgServiceManagement =
                ServiceConfigurationFactory.CreateManagement(
                    new Uri("https://crm.xyz.com/Dev/XRMServices/2011/Organization.svc"));


            AuthenticationCredentials authCredentials = new AuthenticationCredentials();
            authCredentials.ClientCredentials.UserName.UserName = "xyz\\admin";
            authCredentials.ClientCredentials.UserName.Password = "1234pwd";
            AuthenticationCredentials tokenCredentials = orgServiceManagement.Authenticate(authCredentials);

            OrganizationServiceProxy  organizationServiceProxy = new OrganizationServiceProxy(orgServiceManagement, tokenCredentials.SecurityTokenResponse);


            organizationServiceProxy.EnableProxyTypes();
            IOrganizationService newCrmService = (IOrganizationService)organizationServiceProxy;

            Guid userGuid = ((WhoAmIResponse)newCrmService.Execute(new WhoAmIRequest())).UserId;

            log.Info($"Guid of logged user with  orgServiceManagement {userGuid}");

When I run this code locally, i could communicate with CRM and can perform operations.

But when I run the same code on azure it gives me below error

"message": "Exception while executing function: Function1 -> Metadata contains a reference that cannot be resolved: 'crm.xyz.com/.../Organization.svc. -> Unable to connect to the remote server -> An attempt was made to access a socket in a way forbidden by its access permissions 127.0.0.5:443

I looked into Google and found some articles which takes me closer 

  1.  links says using line     ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; will solve the issue.
  2. Above line did not helped.
  3. Also I am using Azure function Version 1, reason I am referencing Dynamics 8.2 sdk and this is possible only in Azure function V1 as it is based on .net framework.
  4. Azure function version 2 is based on .net core and hence we cannot ref dynamics assembly.
  5.  Articles like these and many more 
    says adding project.json file helped. I did that but did not worked for me.

What I think could be issue with me are below

  1. As it is onPrem and IFD facing, I need VPN to use CRM, maybe this is an issue?
  2. There is Pub certificate against CRM which we use. This certificate has been already added to  Azure function with ssl/tls. Maybe this is an issue?
  3. Maybe somewhere in code and assembly dependencies for azure function I am missing?

    Does anyone have any leads for the issue

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans