Now we will see how the same task is accomplished in CRM 2011
If we put it in a method;
public static IOrganizationService getService() { ClientCredentials _cred = new ClientCredentials(); _cred.Windows.ClientCredential = new NetworkCredential("CRM_ADMIN_01", "F1xit@OR5", "CRMBIZDOMAIN"); string _url = "http://crmbiz:5555/abcltd/XRMServices/2011/Organization.svc"; OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(new Uri(_url), null, _cred, null); return (IOrganizationService)serviceProxy; }
Now the calling part;
This comment has been removed by the author.
ReplyDeletePlease find more descriptive article here;
ReplyDeletehttp://axforum.info/forums/showthread.php?t=38211
private IOrganizationService CRMService()
ReplyDelete{
try
{
string username = System.Configuration.ConfigurationManager.AppSettings["domain"] + @"\" + System.Configuration.ConfigurationManager.AppSettings["user"];
string password = System.Configuration.ConfigurationManager.AppSettings["password"];
var userCredentials = new ClientCredentials();
userCredentials.UserName.UserName = username;
userCredentials.UserName.Password = password;
string orgUrl = System.Configuration.ConfigurationManager.AppSettings["url"];
string discoveryUrl = System.Configuration.ConfigurationManager.AppSettings["disurl"];
ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
IServiceConfiguration discoveryConfiguration = ServiceConfigurationFactory.CreateConfiguration(new System.Uri(discoveryUrl));
SecurityTokenResponse userResponseWrapper = discoveryConfiguration.Authenticate(userCredentials);
var _discServiceProxy = new DiscoveryServiceProxy(discoveryConfiguration, userResponseWrapper);
IServiceConfiguration serviceConfiguration = ServiceConfigurationFactory.CreateConfiguration(new System.Uri(orgUrl));
var serviceProxy = new OrganizationServiceProxy(serviceConfiguration,userResponseWrapper);
serviceProxy.EnableProxyTypes();
return (IOrganizationService)serviceProxy;
}
catch (Exception ex) {return null; }
}
Where SvcHelper came from? I trying to follow your example, but i dont know the context of SvcHelper...
ReplyDeleteSorry for not elaborating.
DeleteI have written this method as a static method in a class. In fact, you can call this without initiating an object.
In fact, this is how it should be within a class called SvcHelper.
public class svcHelper
{
public static IOrganizationService getService()
{
}
}
Oh thanks, I get it :)
Delete