locked
CRM4 Web Service within a Plugin RRS feed

  • Question

  • What is the best way to use the CRM web Service within a CRM 4.0 plugin.

    In order to create custom entity objects I need to reference the CRM Web Service at http://<ServerName>/MSCrmServices/2007/CrmServiceWsdl.aspx.  The dyanamic/custom entitiy objects created from this web service are of type CustomPlugins.CrmSdk.DynamicEntity (Where CustomPlugins is the namespace of my plugin and CrmSdk is the reference to the CRM Web Service).  However, plugins require Microsoft.Crm.Sdk which creates objects of type Microsoft.Crm.Sdk.DynamicEntity.  the DynamicEntity passed through the plugin context is also Microsoft.Crm.Sdk.DynamicEntity.  So, I am unable to convert the DynamicEntity from the plugin to a CustomEntity.

    Also the plugin context.CreateCrmService returns an ICrmService that does not accept anything but Microsoft.Crm.Sdk.BusinessEntities.  The SDK says to use context.CreateCrmService because it already has the correct url and organization. So how am I supposed to pass it my custom entites?
    Friday, January 18, 2008 9:04 PM

Answers

  • If using context.CreateCrmService then I think you have to use Microsoft.Crm.Sdk and Microsoft.Crm.SdkTypeProxy, rather than the web reference  (http://<ServerName>/MSCrmServices/2007/CrmServiceWsdl.aspx). As far as I see it that means you have to use dynamic entities, rather than strongly typed ones for your custom entity

    Sunday, January 20, 2008 4:58 PM
    Moderator

All replies

  • If using context.CreateCrmService then I think you have to use Microsoft.Crm.Sdk and Microsoft.Crm.SdkTypeProxy, rather than the web reference  (http://<ServerName>/MSCrmServices/2007/CrmServiceWsdl.aspx). As far as I see it that means you have to use dynamic entities, rather than strongly typed ones for your custom entity

    Sunday, January 20, 2008 4:58 PM
    Moderator
  • See this is the way to use in ASP.Net

     

    here is different ways of the authentication mode present by philip (thanks to him)..

    http://www.philiprichardson.org/blog/post/Part-3-Applications-which-Connect-to-CRM.aspx

     

     

    here is code

            /// <summary>

            /// Windows Authentication

            /// </summary>

            /// <param name="server"></param>

            /// <param name="orgname"></param>

            /// <param name="domain"></param>

            /// <param name="username"></param>

            /// <param name="password"></param>

            public CrmConnect(string server, string orgname, string domain, string username, string password)

            {

                //Network Credential

                NetworkCredential cred = new NetworkCredential();

                cred.Domain = domain;

                cred.UserName = username;

               

                //Discovery

                CrmDiscoveryService disco = new CrmDiscoveryService();

                disco.Credentials = cred;

                disco.Url = server + "/MSCRMServices/2007/AD/CrmDiscoveryService.asmx";

                RetrieveOrganizationsRequest orgrequest = new RetrieveOrganizationsRequest();

                RetrieveOrganizationsResponse orgresponse = (RetrieveOrganizationsResponse)disco.Execute(orgrequest);

     

                OrganizationDetail myorg = new OrganizationDetail();

     

                foreach (OrganizationDetail org in orgresponse.OrganizationDetails)

                {

                    if (org.OrganizationName.ToLower() == orgname)

                    {

                        myorg = org;

                        break;

                    }

                }

     

                //Token

                CrmAuthenticationToken token = new CrmAuthenticationToken();

                token.AuthenticationType = 0;

                token.OrganizationName = myorg.OrganizationName;

     

                //Services

                service = new CrmService();

                service.CrmAuthenticationTokenValue = token;

                service.Credentials = cred;

                service.Url = myorg.CrmServiceUrl;

                meta = new MetadataService();

                meta.CrmAuthenticationTokenValue = token;

                meta.Credentials = cred;

                meta.Url = myorg.CrmMetadataServiceUrl;

     

                //Other Properties

                webappurl = myorg.WebApplicationUrl;

                friendlyname = myorg.FriendlyName;

                organizationid = myorg.OrganizationId;

                organizationname = orgname;

            }

     

           

     

     

    Regards,

    Imran

     

    http://microsoftcrm3.blogspot.com

     

    Monday, January 21, 2008 6:10 AM
    Moderator
  • It seems a bit rediculous that you can't convert the DynamicEntity from the plugin context to a BusinessEntity from the web service.  With as awkward as it is to re-deploy and debug these plugins (have you tried writing a decent uint test for these?), it's nice to have the intellisense and strongly typed objects that the web service uses.  There's got to be a better way to handle this.
    Monday, January 21, 2008 4:06 PM
  • You can use plugin debuger from CRM SDK.

     

    http://blogs.msdn.com/jonasd/archive/2007/11/05/plugin-example-a-simple-logger.aspx

     

    see this example, also download latest CRM SDK 4.0.1 have nice walkthrough.

     

    Best Regards,

    Imran

     

    http://microsoftcrm3.blogspot.com

     

     

    Friday, January 25, 2008 2:58 PM
    Moderator