Answered by:
MSCRM SDK Sample: How to run the sample using Proxy?

Question
-
Hi Tech friends?
MSCRM SDK Sample: How to run the sample using Proxy?
I have to run the SDK using proxy as default network does not allow the SDK to work.
When I try to run using proxy,
DiscoveryServiceProxy -
GetDiscoveryProxy() method throws error saying "proxy authentication failed 407. How do I run this method using proxy?
-Jai
Tuesday, March 27, 2012 2:28 PM
Answers
-
I got it resolved by creating custom proxy library using IWebProxy interface. This library I referred in .exe.config. You can supply user credentials of proxy as well. This is not possible in IE settings. Thus, resolved it.
-Jai
- Marked as answer by Jai Mallesh Babu Wednesday, March 6, 2013 1:35 PM
Wednesday, March 6, 2013 1:35 PM
All replies
-
You should post your code here to help us troubleshoot the issue.
Jamie Miley
Check out my about.me profile!
http://mileyja.blogspot.com
Linked-In Profile
Follow Me on Twitter!Tuesday, March 27, 2012 2:50 PMModerator -
Here is the code:
private DiscoveryServiceProxy GetDiscoveryProxy() { IServiceManagement<IDiscoveryService> serviceManagement = ServiceConfigurationFactory.CreateManagement<IDiscoveryService>( config.DiscoveryUri); // Get the EndpointType. config.EndpointType = serviceManagement.AuthenticationType; // Get the logon credentials. config.Credentials = GetUserLogonCredentials(); AuthenticationCredentials authCredentials = new AuthenticationCredentials(); if (!String.IsNullOrWhiteSpace(config.UserPrincipalName)) { // Try to authenticate the Federated Identity organization with UserPrinicipalName. authCredentials.UserPrincipalName = config.UserPrincipalName; try { AuthenticationCredentials tokenCredentials = serviceManagement.Authenticate( authCredentials); DiscoveryServiceProxy discoveryProxy = new DiscoveryServiceProxy(serviceManagement, tokenCredentials.SecurityTokenResponse); // Checking authentication by invoking some SDK methods. OrganizationDetailCollection orgs = DiscoverOrganizations(discoveryProxy); return discoveryProxy; } catch (System.ServiceModel.Security.SecurityAccessDeniedException ex) { // If authentication failed using current UserPrincipalName, // request UserName and Password to try to authenticate using user credentials. if (ex.Message.Contains("Access is denied.")) { config.AuthFailureCount += 1; authCredentials.UserPrincipalName = String.Empty; config.Credentials = GetUserLogonCredentials(); } else { throw ex; } } // You can also catch other exceptions to handle a specific situation in your code, for example, // System.ServiceModel.Security.ExpiredSecurityTokenException // System.ServiceModel.Security.MessageSecurityException // System.ServiceModel.Security.SecurityNegotiationException } // Resetting credentials in the AuthenicationCredentials. if (config.EndpointType != AuthenticationProviderType.ActiveDirectory) { authCredentials = new AuthenticationCredentials(); authCredentials.ClientCredentials = config.Credentials; if (config.EndpointType == AuthenticationProviderType.LiveId) { authCredentials.SupportingCredentials = new AuthenticationCredentials(); authCredentials.SupportingCredentials.ClientCredentials = config.DeviceCredentials; } // Try to authenticate with the user credentials. AuthenticationCredentials tokenCredentials1 = serviceManagement.Authenticate( authCredentials); return new DiscoveryServiceProxy(serviceManagement, tokenCredentials1.SecurityTokenResponse); } // For an on-premises environment. return new DiscoveryServiceProxy(serviceManagement, config.Credentials); }
The code fails at:
IServiceManagement<IDiscoveryService> serviceManagement =
ServiceConfigurationFactory.CreateManagement<IDiscoveryService>(
config.DiscoveryUri);The SDK sample (importing records) works fine in my home network. But in my company network, it fails in above line.
I have to use proxy. How do I use proxy? For webrequest object, I can use proxy (webrequest.proxy). But for above serviceManagement (discovery service) there is no provision to add proxy? How do I configure proxy with authentication for above method?
Thanks,
-Jai
- Edited by Jai Mallesh Babu Thursday, March 29, 2012 7:36 AM small change
Thursday, March 29, 2012 7:34 AM -
This one kind of fell through the cracks, did you ever get it resolved?
Jamie Miley
Check out RBA Today!
Check out my about.me profile!
http://mileyja.blogspot.com
Linked-In Profile
Follow Me on Twitter!Tuesday, March 5, 2013 12:58 PMModerator -
I got it resolved by creating custom proxy library using IWebProxy interface. This library I referred in .exe.config. You can supply user credentials of proxy as well. This is not possible in IE settings. Thus, resolved it.
-Jai
- Marked as answer by Jai Mallesh Babu Wednesday, March 6, 2013 1:35 PM
Wednesday, March 6, 2013 1:35 PM -
Wednesday, March 6, 2013 6:09 PMModerator