locked
Regarding Custom ASP.NET application for CRM RRS feed

  • Question

  • Hi,

    Regarding Custom ASP.NET application for CRM

     

    We have client asking for a WEB Interface that can interact with CRM. We tried this and is working fine with VS in-built Web server. But when we deploy the application on IIS and on a different website it is not working.

     

    Can anyone tell me, how to host/deploy the website on the same web server where the CRM web server is installed, but on a different website.


    Regards,
    Kishan

    Monday, July 20, 2009 12:36 PM

Answers

  • Hi Kishan,

    I suggest to take the following steps
     - Create a new App Pool dedicated for your Web App not the CRM App Pool
     - Create a new Web Site[You can use existing one as well]
     - Create a new Virtual Directory and mark it as an Application[Right Click -> Properties -> Application Settings -> Set your application name, execution permission and set the app pool to the one we created earlier]
     - Configure the application to use Windows Authentication[Right Click -> Properties -> Directory Security -> Edit... -> Check Integrated Windows Authentication, Uncheck Anonymous Authentication]
     - Open web.config of your web application, enable Integrated Windows Authentication and set Impersonation to true.
    <authentication mode="Windows"/>
    <identity impersonate="true"/>

    Let me know if you are need further help with this. 
    Regards,
    Chinmay
    http://metrix.blogspot.com
    Monday, July 20, 2009 12:44 PM
  • You can follow the steps which Chinmay has mention above. After deployment you might face few issues which can resolved using below link.
    http://blogs.msdn.com/cesardelatorre/archive/2007/11/14/how-to-deploy-your-own-asp-net-application-within-the-same-dynamics-crm-4-0-iis-website.aspx

    Hope it helps.
    Jai Ho CRM http://mscrmkb.blogspot.com Skype - amol.gholap
    Monday, July 20, 2009 12:49 PM
  • You can follow the steps which Chinmay has mention above. After deployment you might face few issues which can resolved using below link.
    http://blogs.msdn.com/cesardelatorre/archive/2007/11/14/how-to-deploy-your-own-asp-net-application-within-the-same-dynamics-crm-4-0-iis-website.aspx

    Hope it helps.
    Jai Ho CRM http://mscrmkb.blogspot.com Skype - amol.gholap

    Sorry to say this Amol, but that particular setting is required as per the blog itself, the very first line says :

    There is a common issue when trying to deploy your own ASP.NET application within the same CRM 4.0 IIS WebSite.

    And Kishan wants to deploy it in a totally different web site, so I don't think that he needs to do any of these settings.
    Regards,
    Chinmay
    http://metrix.blogspot.com
    Monday, July 20, 2009 1:01 PM
  • Hi, Kishanraj.

    Switch on trace and give error log when you try to open this webpage.
    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Monday, July 20, 2009 1:08 PM
    Moderator
  • Hi, GF.

    Check this url .
    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Monday, July 20, 2009 1:22 PM
    Moderator
  • Hi Kishan,

    As suggested by Andriy, please enable DevErrors via Crm's web.config and/or enable trace and upload the trace to SkyDrive and let us know. Also, in case you want to deploy it under CRM's web, in that case you will have to follow steps shown by Amol. :)
    Regards,
    Chinmay
    http://metrix.blogspot.com
    Monday, July 20, 2009 1:22 PM
  • Hi Golden Fish,

    Did you try to debug this code? If yes, what error you see when you put

    try

    {

    Guid id = service.Create(emp);

    }
    catch(SoapException soapException) {...}

    Just debug the code, and let us know what do you get in SoapException's Details.
    Regards,
    Chinmay
    http://metrix.blogspot.com
    Monday, July 20, 2009 2:04 PM
  • Hi, GF.

    Try to create a token in following way:

    service.CrmAuthenticationTokenValue = CrmAuthenticationToken.ExtractCrmAuthenticationToken(Context, "OrgName");
    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Monday, July 20, 2009 2:13 PM
    Moderator
  • Hi, GF.

    To make it workable you have to modify it in following way:

    1. Remove  <authentication mode="Windows" /> section.
    2. Add following section section under system.web node:

        <httpModules>
          <add name="MapOrg" type="Microsoft.Crm.MapOrgEngine, Microsoft.Crm, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          <add name="CrmAuthentication" type="Microsoft.Crm.Authentication.AuthenticationEngine, Microsoft.Crm, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        </httpModules>

    This is my default web.config I use to develop web pages for CRM:

    <?xml version="1.0"?>
    <configuration>
    	<appSettings/>
    	<connectionStrings/>
    	<system.web>
        <httpModules>
          <add name="MapOrg" type="Microsoft.Crm.MapOrgEngine, Microsoft.Crm, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          <add name="CrmAuthentication" type="Microsoft.Crm.Authentication.AuthenticationEngine, Microsoft.Crm, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        </httpModules>
        <identity impersonate="true"/>
        <compilation debug="true">
    			<assemblies>
    				<add assembly="Microsoft.Crm.Sdk, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    				<add assembly="Microsoft.Crm.SdkTypeProxy, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
          </assemblies>
        </compilation>
    	</system.web>
    </configuration>
    
    Also there are one issue with CRM pages - to use web services you have to register Microsoft.CRM.WebServices.dll in the GAC.

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Monday, July 20, 2009 2:39 PM
    Moderator
  • Hi, GF.

    This is webpage codebehind:

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using Microsoft.Crm.SdkTypeProxy;
    using Microsoft.Win32;
    using Microsoft.Crm.Sdk.Query;
    using Microsoft.Crm.Sdk;
    
    public partial class CloneExecutor : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Clear();
    
            try
            {
                string orgName = string.Empty;
                string entityId = string.Empty;
    
                #region Parameters Collecting
    
                if (string.IsNullOrEmpty(Request.QueryString["orgName"]))
                    throw new Exception("No Organization Name in Request");
    
                orgName = Request.QueryString["orgName"];
    
                #endregion Parameters Collecting
    
                using (new CrmImpersonator())
                {
    
                    #region Service Retrieving
    
                    CrmService crmService = new CrmService();
                    crmService.UseDefaultCredentials = true;
                    crmService.CrmAuthenticationTokenValue = CrmAuthenticationToken.ExtractCrmAuthenticationToken(Context, orgName);
                    crmService.Url = (string)(Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\MSCRM").GetValue("ServerUrl")) + "/2007/crmservice.asmx";
    
                    #endregion Service Retrieving
    
                    DynamicEntity record = new DynamicEntity("new_entity");
                    record["new_name"] = "some text";
    
                    crmService.Create(record);
                }
            }
            catch (System.Web.Services.Protocols.SoapException soapExc)
            {
                Response.Write(soapExc.Detail.InnerXml);
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
    }
    
    This is aspx page:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="CloneExecutor.aspx.cs" Inherits="CloneExecutor" %>


    This is Web.Config file:

    <?xml version="1.0"?>
    <configuration>
    	<appSettings/>
    	<connectionStrings/>
    	<system.web>
        <httpModules>
          <add name="MapOrg" type="Microsoft.Crm.MapOrgEngine, Microsoft.Crm, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          <add name="CrmAuthentication" type="Microsoft.Crm.Authentication.AuthenticationEngine, Microsoft.Crm, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        </httpModules>
        <identity impersonate="true"/>
        <compilation debug="true">
    			<assemblies>
    				<add assembly="Microsoft.Crm.Sdk, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    				<add assembly="Microsoft.Crm.SdkTypeProxy, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
          </assemblies>
        </compilation>
    	</system.web>
    </configuration>
    

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Monday, July 20, 2009 2:44 PM
    Moderator
  • Hi, GF.

    Organization name passing to webpage as a parameter:

    string
     orgName = string
    .Empty;
    orgName = Request.QueryString["orgName" ];


    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Monday, July 20, 2009 4:33 PM
    Moderator
  • Hi, GF.

    1. On your developed custom page in VS click publish web site.
    2. Predefine directory for its publishing.
    3. Copy retrieved files to the server with MS CRM.
    4. In ISV directory of web site create directory for your custom page and copy .config, .aspx files onto it.
    5. Open Bin directory of CRM website and copy retrieved dll onto it.
    6. Test your custom page.

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Tuesday, July 21, 2009 6:36 AM
    Moderator

All replies

  • Hi Kishan,

    I suggest to take the following steps
     - Create a new App Pool dedicated for your Web App not the CRM App Pool
     - Create a new Web Site[You can use existing one as well]
     - Create a new Virtual Directory and mark it as an Application[Right Click -> Properties -> Application Settings -> Set your application name, execution permission and set the app pool to the one we created earlier]
     - Configure the application to use Windows Authentication[Right Click -> Properties -> Directory Security -> Edit... -> Check Integrated Windows Authentication, Uncheck Anonymous Authentication]
     - Open web.config of your web application, enable Integrated Windows Authentication and set Impersonation to true.
    <authentication mode="Windows"/>
    <identity impersonate="true"/>

    Let me know if you are need further help with this. 
    Regards,
    Chinmay
    http://metrix.blogspot.com
    Monday, July 20, 2009 12:44 PM
  • You can follow the steps which Chinmay has mention above. After deployment you might face few issues which can resolved using below link.
    http://blogs.msdn.com/cesardelatorre/archive/2007/11/14/how-to-deploy-your-own-asp-net-application-within-the-same-dynamics-crm-4-0-iis-website.aspx

    Hope it helps.
    Jai Ho CRM http://mscrmkb.blogspot.com Skype - amol.gholap
    Monday, July 20, 2009 12:49 PM
  • Hi Kishan,

    Are you authenticating your web service instance properly?

      CrmService service = new CrmService();

            try
            {
                CrmAuthenticationToken token = new CrmAuthenticationToken();
                token.AuthenticationType = 0;
                token.OrganizationName = Config.WebServiceOrganization;


                service.Url = Config.WebServiceUrl;
                service.CrmAuthenticationTokenValue = token;
                service.Credentials = new NetworkCredential(Config.WebServiceUsername,
                                                            Config.WebServicePassword,
                                                            Config.WebServiceDomain);
            }
            catch (Exception)
            {

            }

    If you are already authenticating (and not using the default credentials), perhaps you can explain the problem in a bit more detail or supply the specific error message you are receiving...

    Monday, July 20, 2009 12:50 PM
  • You can follow the steps which Chinmay has mention above. After deployment you might face few issues which can resolved using below link.
    http://blogs.msdn.com/cesardelatorre/archive/2007/11/14/how-to-deploy-your-own-asp-net-application-within-the-same-dynamics-crm-4-0-iis-website.aspx

    Hope it helps.
    Jai Ho CRM http://mscrmkb.blogspot.com Skype - amol.gholap

    Sorry to say this Amol, but that particular setting is required as per the blog itself, the very first line says :

    There is a common issue when trying to deploy your own ASP.NET application within the same CRM 4.0 IIS WebSite.

    And Kishan wants to deploy it in a totally different web site, so I don't think that he needs to do any of these settings.
    Regards,
    Chinmay
    http://metrix.blogspot.com
    Monday, July 20, 2009 1:01 PM
  • Hi Chinmay,

    i have followed the steps mentioned by you and it worked when i created a virtual directory on the default website but it did not work on Microsoft Dynamics CRM website.

    is there any other way to host it on CRM website. when i hosted on crm website and tried to perform the create operation i got the following error.


    http://i616.photobucket.com/albums/tt248/rajsekhar311/error-1.jpg


    Regards,
    Kishan.

    Monday, July 20, 2009 1:06 PM
  • Hi, Kishanraj.

    Switch on trace and give error log when you try to open this webpage.
    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Monday, July 20, 2009 1:08 PM
    Moderator
  • hi chinmay,

    i deployed it on the same website Default Website it is working fine. when i does this on crm website it is showing the above error.

    regards,
    kishan
    Monday, July 20, 2009 1:13 PM
  • Hi a33ik,

    Where can i found that registry values?
    Monday, July 20, 2009 1:20 PM
  • Hi, GF.

    Check this url .
    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Monday, July 20, 2009 1:22 PM
    Moderator
  • Hi Kishan,

    As suggested by Andriy, please enable DevErrors via Crm's web.config and/or enable trace and upload the trace to SkyDrive and let us know. Also, in case you want to deploy it under CRM's web, in that case you will have to follow steps shown by Amol. :)
    Regards,
    Chinmay
    http://metrix.blogspot.com
    Monday, July 20, 2009 1:22 PM
  • Hi a33ik,

    The following error log

    # CRM Tracing Version 2.0
    # LocalTime: 2009-07-20 19:15:10.5
    # Categories:
    # CallStackOn: No
    # ComputerName: B2BSRV-25
    # CRMVersion: 4.0.7333.1408
    # DeploymentType: OnPremise
    # ScaleGroup:
    # ServerRole: AppServer, AsyncService, DiscoveryService, WebService, ApiServer, HelpServer, DeploymentService

    [2009-07-20 19:16:42.2] Process: w3wp |Organization:aafe5dbd-e63d-de11-bff8-001fe25c8489 |Thread:    5 |Category: Application |User: 00000000-0000-0000-0000-000000000000 |Level: Error | ErrorInformation.LogError
    >MSCRM Error Report:
    --------------------------------------------------------------------------------------------------------
    Error: Exception of type 'System.Web.HttpUnhandledException' was thrown.

    Error Message: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Error Details: Exception of type 'System.Web.HttpUnhandledException' was thrown.

    Source File: Not available

    Line Number: Not available

    Request URL: http://b2bsrv-25:5555/default.aspx

    Stack Trace Info: [InvalidOperationException: CRM Parameter Filter - Invalid parameter '__EVENTTARGET=GridView1' in Request.Form on page /default.aspx
    The raw request was 'POST /default.aspx' called from http://b2bsrv-25:5555/Test.]
       at Microsoft.Crm.Application.ParameterFilter.ValidateParameter(Page page, ArrayList parameterCollection, String key, String value, String collectionName, EntityType pageEntityType)
       at Microsoft.Crm.Application.ParameterFilter.ValidateParameters(Page page, EntityType pageEntityType, Boolean alwaysEnableParameterChecking)
       at Microsoft.Crm.Application.ParameterFilter.ValidateParameters(Page page, EntityType pageEntityType)
       at Microsoft.Crm.Application.Controls.AppPage.ValidatePageParameters()
       at Microsoft.Crm.Application.Controls.AppPage.OnInit(EventArgs e)
       at System.Web.UI.Control.InitRecursive(Control namingContainer)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

    [HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown.]
       at System.Web.UI.Page.HandleError(Exception e)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       at System.Web.UI.Page.ProcessRequest()
       at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
       at System.Web.UI.Page.ProcessRequest(HttpContext context)
       at ASP.default_aspx.ProcessRequest(HttpContext context)
       at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
       at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)


    The above error occured when i am trying to create a record for custom entity from website.

     

    Monday, July 20, 2009 1:46 PM
  • Hi Golden Fish,

    Can you post the code you guys are using to create the record?
    Regards,
    Chinmay
    http://metrix.blogspot.com
    Monday, July 20, 2009 1:53 PM
  • Hi chinmay,

    The following is the code


    DynamicEntity emp = new DynamicEntity();
                emp.Name = "new_employeedetails";   
           
                StringProperty empname = new StringProperty();
                empname.Name = "new_employeename";
                empname.Value = TextBox1.Text;

                StringProperty empid = new StringProperty();
                empid.Name = "new_employeeid";
                empid.Value = TextBox2.Text;

                StringProperty desg = new StringProperty();
                desg.Name = "new_designation";
                desg.Value = TextBox3.Text;

               
                CrmMoneyProperty sal = new CrmMoneyProperty();
                sal.Name = "new_empsalary";
                sal.Value = new CrmMoney();
                sal.Value.Value = Convert.ToDecimal(TextBox4.Text);
                         
                CrmDateTimeProperty doj = new CrmDateTimeProperty();
                doj.Name = "new_dateofjoin";
                doj.Value = new CrmDateTime();
                doj.Value.Value = TextBox5.Text;

                PicklistProperty gen = new PicklistProperty();
                gen.Name = "new_gender";
                gen.Value = new Picklist();
                gen.Value.name = DropDownList1.SelectedItem.Text;
                gen.Value.Value = int.Parse(DropDownList1.SelectedValue);

                StringProperty addr = new StringProperty();
                addr.Name = "new_address";
                addr.Value = TextBox6.Text;
               
                emp.Properties.Add(empname);
                emp.Properties.Add(empid);
                emp.Properties.Add(desg);
                emp.Properties.Add(sal);
                emp.Properties.Add(doj);
                emp.Properties.Add(gen);
                emp.Properties.Add(addr);

                Guid id = service.Create(emp);

    Monday, July 20, 2009 1:55 PM
  • Hi, GF.

    This is not full code. Also CrmService creation code is needed. Do you use  using(new CrmImpersonator()){} code?

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Monday, July 20, 2009 1:58 PM
    Moderator
  • Hi Golden Fish,

    Did you try to debug this code? If yes, what error you see when you put

    try

    {

    Guid id = service.Create(emp);

    }
    catch(SoapException soapException) {...}

    Just debug the code, and let us know what do you get in SoapException's Details.
    Regards,
    Chinmay
    http://metrix.blogspot.com
    Monday, July 20, 2009 2:04 PM
  • Yes, The following is that code

    CrmAuthenticationToken

     

    token = new CrmAuthenticationToken();

    token.OrganizationName =

    "OrgName";

    token.AuthenticationType = 0;

     

    CrmService service = new CrmService();

    service.CrmAuthenticationTokenValue = token;

    service.Credentials = System.Net.

    CredentialCache.DefaultCredentials;

    service.Url =

    "http://<server name>:5555/mscrmservices/2007/crmservice.asmx";

    Monday, July 20, 2009 2:09 PM
  • Hi, GF.

    Try to create a token in following way:

    service.CrmAuthenticationTokenValue = CrmAuthenticationToken.ExtractCrmAuthenticationToken(Context, "OrgName");
    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Monday, July 20, 2009 2:13 PM
    Moderator
  • Hi a33ik,

    Is it require to change the web.config values?.


    Hi Chinmay,

    In debugging i didnt get any errors. My functionality doesnt work when i host it in CRM Website only. In Default website also its working fine. I am getting problem in CRM Website only.

    Monday, July 20, 2009 2:22 PM
  • Hi, GF.

    It is not required to change web.config.

    Could you give your web.config?

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Monday, July 20, 2009 2:30 PM
    Moderator
  • Hi a33ik,

    <?xml version="1.0" encoding="UTF-8"?>
    <!--
        Note: As an alternative to hand editing this file you can use the
        web admin tool to configure settings for your application. Use
        the Website->Asp.Net Configuration option in Visual Studio.
        A full list of settings and comments can be found in
        machine.config.comments usually located in
        \Windows\Microsoft.Net\Framework\v2.x\Config
    -->
    <configuration>
      <appSettings>
      <add key="connectionString" value="Data Source=<server name>;Initial Catalog=<database name>;Integrated Security=True;" />
     </appSettings>
     <connectionStrings/>
     <system.web>
        <customErrors mode="Off" />

         
        <identity impersonate="true" />
      <!--
                Set compilation debug="true" to insert debugging
                symbols into the compiled page. Because this
                affects performance, set this value to true only
                during development.
            -->
      <compilation debug="true">
      </compilation>
      <!--
                The <authentication> section enables configuration
                of the security authentication mode used by
                ASP.NET to identify an incoming user.
            -->
      <authentication mode="Windows" />
      <!--
                The <customErrors> section enables configuration
                of what to do if/when an unhandled error occurs
                during the execution of a request. Specifically,
                it enables developers to configure html error pages
                to be displayed in place of a error stack trace.

            <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
                <error statusCode="403" redirect="NoAccess.htm" />
                <error statusCode="404" redirect="FileNotFound.htm" />
            </customErrors>
            -->
     </system.web>
        <system.webServer>
            <defaultDocument>
                <files>
                    <add value="Default.aspx" />
                </files>
            </defaultDocument>
        </system.webServer>
    </configuration>

    Monday, July 20, 2009 2:35 PM
  • Hi, GF.

    To make it workable you have to modify it in following way:

    1. Remove  <authentication mode="Windows" /> section.
    2. Add following section section under system.web node:

        <httpModules>
          <add name="MapOrg" type="Microsoft.Crm.MapOrgEngine, Microsoft.Crm, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          <add name="CrmAuthentication" type="Microsoft.Crm.Authentication.AuthenticationEngine, Microsoft.Crm, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        </httpModules>

    This is my default web.config I use to develop web pages for CRM:

    <?xml version="1.0"?>
    <configuration>
    	<appSettings/>
    	<connectionStrings/>
    	<system.web>
        <httpModules>
          <add name="MapOrg" type="Microsoft.Crm.MapOrgEngine, Microsoft.Crm, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          <add name="CrmAuthentication" type="Microsoft.Crm.Authentication.AuthenticationEngine, Microsoft.Crm, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        </httpModules>
        <identity impersonate="true"/>
        <compilation debug="true">
    			<assemblies>
    				<add assembly="Microsoft.Crm.Sdk, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    				<add assembly="Microsoft.Crm.SdkTypeProxy, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
          </assemblies>
        </compilation>
    	</system.web>
    </configuration>
    
    Also there are one issue with CRM pages - to use web services you have to register Microsoft.CRM.WebServices.dll in the GAC.

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Monday, July 20, 2009 2:39 PM
    Moderator
  • Hi a33ik,

    Could you give me the code for insert a single value using sdk which is able to run on CRM Website. Please give me all the code including namespaces.

    Regards,
    GF
    Monday, July 20, 2009 2:39 PM
  • Hi, GF.

    This is webpage codebehind:

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using Microsoft.Crm.SdkTypeProxy;
    using Microsoft.Win32;
    using Microsoft.Crm.Sdk.Query;
    using Microsoft.Crm.Sdk;
    
    public partial class CloneExecutor : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Clear();
    
            try
            {
                string orgName = string.Empty;
                string entityId = string.Empty;
    
                #region Parameters Collecting
    
                if (string.IsNullOrEmpty(Request.QueryString["orgName"]))
                    throw new Exception("No Organization Name in Request");
    
                orgName = Request.QueryString["orgName"];
    
                #endregion Parameters Collecting
    
                using (new CrmImpersonator())
                {
    
                    #region Service Retrieving
    
                    CrmService crmService = new CrmService();
                    crmService.UseDefaultCredentials = true;
                    crmService.CrmAuthenticationTokenValue = CrmAuthenticationToken.ExtractCrmAuthenticationToken(Context, orgName);
                    crmService.Url = (string)(Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\MSCRM").GetValue("ServerUrl")) + "/2007/crmservice.asmx";
    
                    #endregion Service Retrieving
    
                    DynamicEntity record = new DynamicEntity("new_entity");
                    record["new_name"] = "some text";
    
                    crmService.Create(record);
                }
            }
            catch (System.Web.Services.Protocols.SoapException soapExc)
            {
                Response.Write(soapExc.Detail.InnerXml);
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
    }
    
    This is aspx page:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="CloneExecutor.aspx.cs" Inherits="CloneExecutor" %>


    This is Web.Config file:

    <?xml version="1.0"?>
    <configuration>
    	<appSettings/>
    	<connectionStrings/>
    	<system.web>
        <httpModules>
          <add name="MapOrg" type="Microsoft.Crm.MapOrgEngine, Microsoft.Crm, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          <add name="CrmAuthentication" type="Microsoft.Crm.Authentication.AuthenticationEngine, Microsoft.Crm, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        </httpModules>
        <identity impersonate="true"/>
        <compilation debug="true">
    			<assemblies>
    				<add assembly="Microsoft.Crm.Sdk, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    				<add assembly="Microsoft.Crm.SdkTypeProxy, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
          </assemblies>
        </compilation>
    	</system.web>
    </configuration>
    

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Monday, July 20, 2009 2:44 PM
    Moderator
  • Hi a33ik,

    In the above where can i specify the organization name?
    Monday, July 20, 2009 4:28 PM
  • Hi, GF.

    Organization name passing to webpage as a parameter:

    string
     orgName = string
    .Empty;
    orgName = Request.QueryString["orgName" ];


    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Monday, July 20, 2009 4:33 PM
    Moderator
  • Hi a33ik,

    I have tried your code. I am getting the following error.

    0x80040217 systemuser With Id = 0f1241e5-e63d-de11-bff8-001fe25c8489 Does Not Exist Platform

    I dont have a user with the above ID im my CRM.

    The following is my code.

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using Microsoft.Crm.SdkTypeProxy;
    using Microsoft.Win32;
    using Microsoft.Crm.Sdk.Query;
    using Microsoft.Crm.Sdk;


    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Clear();

            try
            {
                string orgName = "B2BLIVE8";
                
                using (new CrmImpersonator())
                {

                    #region Service Retrieving

                    CrmService crmService = new CrmService();
                    crmService.UseDefaultCredentials = true;
                    crmService.CrmAuthenticationTokenValue = CrmAuthenticationToken.ExtractCrmAuthenticationToken(Context, orgName);
                    crmService.Url = (string)(Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\MSCRM").GetValue("ServerUrl")) + "/2007/crmservice.asmx";

                    #endregion Service Retrieving

                    DynamicEntity record = new DynamicEntity("new_employeedetails");
                    record["new_employeename"] = "phani kumar";

                    crmService.Create(record);
                }
            }
            catch (System.Web.Services.Protocols.SoapException soapExc)
            {
                Response.Write(soapExc.Detail.InnerXml);
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }

        }
    }

    Regards,
    GF

    Tuesday, July 21, 2009 4:15 AM
  • hi a33ik and chinmay,

    should we place any dll in crm bin folder?

    regards,
    kishan.
    Tuesday, July 21, 2009 5:32 AM
  • Hi.

    After publishing the web site you have to place dll file to bin folder of MS CRM website.
    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Tuesday, July 21, 2009 6:17 AM
    Moderator
  • Hi Andriy,

    Please look at my code and error i am getting in the above post and let me know if there are any changes.

    Regards
    GF
    Tuesday, July 21, 2009 6:27 AM
  • Hi, GF.

    I've tested this code and it works perfectly.

    Do you run this code from Visual Studio or after deploying website onto MS CRM?

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Tuesday, July 21, 2009 6:29 AM
    Moderator
  • I dont have Visual Studio in server. How can I test?
    Tuesday, July 21, 2009 6:33 AM
  • Hi, GF.

    1. On your developed custom page in VS click publish web site.
    2. Predefine directory for its publishing.
    3. Copy retrieved files to the server with MS CRM.
    4. In ISV directory of web site create directory for your custom page and copy .config, .aspx files onto it.
    5. Open Bin directory of CRM website and copy retrieved dll onto it.
    6. Test your custom page.

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Tuesday, July 21, 2009 6:36 AM
    Moderator
  • Hi andriy,

    I have tested my website as you described in the above post. I gone through all the 6 steps and its working fine, records are inserted. When I host my website in CRM Website its not working fine. An error occured "Invalid Action". The following are the files of my website.


    This is aspx.cs file


    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using Microsoft.Crm.SdkTypeProxy;
    using Microsoft.Win32;
    using Microsoft.Crm.Sdk.Query;
    using Microsoft.Crm.Sdk;


    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {


        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Clear();

            try
            {
                string orgName = "B2BLIVE8";

                using (new CrmImpersonator())
                {

                    #region Service Retrieving

                    CrmService crmService = new CrmService();
                    crmService.UseDefaultCredentials = true;
                    crmService.CrmAuthenticationTokenValue = CrmAuthenticationToken.ExtractCrmAuthenticationToken(Context, orgName);
                    crmService.Url = (string)(Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\MSCRM").GetValue("ServerUrl")) + "/2007/crmservice.asmx";

                    #endregion Service Retrieving

                    DynamicEntity record = new DynamicEntity("new_employeedetails");
                    record["new_employeename"] = TextBox1.Text;
                    record["new_employeeid"] = TextBox2.Text;

                    crmService.Create(record);
                }
            }
            catch (System.Web.Services.Protocols.SoapException soapExc)
            {
                Response.Write(soapExc.Detail.InnerXml);
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
    }

     

    This is .aspx file

    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

    <form id="form1" runat="server">
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    </form>


    This is web.config file

    <?xml version="1.0"?>
    <configuration>
      <appSettings/>
      <connectionStrings/>
      <system.web>
        <httpModules>
          <add name="MapOrg" type="Microsoft.Crm.MapOrgEngine, Microsoft.Crm, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          <add name="CrmAuthentication" type="Microsoft.Crm.Authentication.AuthenticationEngine, Microsoft.Crm, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        </httpModules>
        <identity impersonate="true"/>
        <compilation debug="true">
          <assemblies>
            <add assembly="Microsoft.Crm.Sdk, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add assembly="Microsoft.Crm.SdkTypeProxy, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
          </assemblies>
        </compilation>
      </system.web>
    </configuration>


    The following is the Error Log


    # CRM Tracing Version 2.0
    # LocalTime: 2009-07-21 14:34:49.9
    # Categories:
    # CallStackOn: No
    # ComputerName: B2BSRV-25
    # CRMVersion: 4.0.7333.1408
    # DeploymentType: OnPremise
    # ScaleGroup:
    # ServerRole: AppServer, AsyncService, DiscoveryService, WebService, ApiServer, HelpServer, DeploymentService

    [2009-07-21 14:34:49.9] Process: w3wp |Organization:aafe5dbd-e63d-de11-bff8-001fe25c8489 |Thread:    1 |Category: Application |User: 00000000-0000-0000-0000-000000000000 |Level: Error | ErrorInformation.LogError
    >MSCRM Error Report:
    --------------------------------------------------------------------------------------------------------
    Error: Exception of type 'System.Web.HttpUnhandledException' was thrown.

    Error Number: 0x8004A106

    Error Message: The key specified to compute a hash value is expired, only active keys are valid.  Expired Key : CrmKey(Id:b0066917-e45b-de11-bff8-001fe25c8489, ScaleGroupId:00000000-0000-0000-0000-000000000000, KeyType:CrmWRPCTokenKey, Expired:True, ValidOn:06/18/2009 08:43:28, ExpiresOn:07/21/2009 08:43:28, CreatedOn:06/18/2009 08:43:28, CreatedBy:NT AUTHORITY\NETWORK SERVICE.

    Error Details: The key specified to compute a hash value is expired, only active keys are valid.  Expired Key : CrmKey(Id:b0066917-e45b-de11-bff8-001fe25c8489, ScaleGroupId:00000000-0000-0000-0000-000000000000, KeyType:CrmWRPCTokenKey, Expired:True, ValidOn:06/18/2009 08:43:28, ExpiresOn:07/21/2009 08:43:28, CreatedOn:06/18/2009 08:43:28, CreatedBy:NT AUTHORITY\NETWORK SERVICE.

    Source File: Not available

    Line Number: Not available

    Request URL: <URL>
    Stack Trace Info: [CrmException: The key specified to compute a hash value is expired, only active keys are valid.  Expired Key : CrmKey(Id:b0066917-e45b-de11-bff8-001fe25c8489, ScaleGroupId:00000000-0000-0000-0000-000000000000, KeyType:CrmWRPCTokenKey, Expired:True, ValidOn:06/18/2009 08:43:28, ExpiresOn:07/21/2009 08:43:28, CreatedOn:06/18/2009 08:43:28, CreatedBy:NT AUTHORITY\NETWORK SERVICE.]
       at Microsoft.Crm.CrmKeyService.ComputeHash(CrmKey key, Guid scaleGroupId, HashParameterBase[] parameters)
       at Microsoft.Crm.CrmKeyService.ComputeHash(CrmKey key, HashParameterBase[] parameters)
       at Microsoft.Crm.Application.Security.WRPCContext..ctor()
       at Microsoft.Crm.Application.Controls.AppPage.ValidateWrpcContext()
       at Microsoft.Crm.Application.Controls.AppPage.OnInit(EventArgs e)
       at System.Web.UI.Control.InitRecursive(Control namingContainer)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

    [HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown.]
       at System.Web.UI.Page.HandleError(Exception e)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       at System.Web.UI.Page.ProcessRequest()
       at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
       at System.Web.UI.Page.ProcessRequest(HttpContext context)
       at ASP.default_aspx.ProcessRequest(HttpContext context)
       at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
       at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)


    [2009-07-21 14:35:08.3] Process: w3wp |Organization:00000000-0000-0000-0000-000000000000 |Thread:    7 |Category: Exception |User: 00000000-0000-0000-0000-000000000000 |Level: Error | CrmException..ctor
     at CrmException..ctor(String message, Exception innerException, Int32 errorCode, Boolean isFlowControlException, Boolean enableTrace)
     at CrmKeyService.ComputeHash(CrmKey key, Guid scaleGroupId, HashParameterBase[] parameters)
     at CrmKeyService.ComputeHash(CrmKey key, HashParameterBase[] parameters)
     at WRPCContext..ctor()
     at AppPage.ValidateWrpcContext()
     at AppPage.OnInit(EventArgs e)
     at Control.InitRecursive(Control namingContainer)
     at Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
     at Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
     at Page.ProcessRequest()
     at Page.ProcessRequestWithNoAssert(HttpContext context)
     at Page.ProcessRequest(HttpContext context)
     at default_aspx.ProcessRequest(HttpContext context)
     at CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
     at HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
     at HttpApplication.ResumeSteps(Exception error)
     at HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
     at HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)
     at HttpRuntime.ProcessRequestNoDemand(HttpWorkerRequest wr)
     at ISAPIRuntime.ProcessRequest(IntPtr ecb, Int32 iWRType)

    Please help me.

    Regards,
    GF

    Tuesday, July 21, 2009 9:15 AM
  • Hi, GF.

    Check that Microsoft Asynchronous Service is run. If not run it.

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Tuesday, July 21, 2009 9:25 AM
    Moderator
  • Hi Andriy,

    There is no problem in Asynchronous Service. Its running.

    Tuesday, July 21, 2009 10:16 AM