Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Create Records in CRM using a standalone web application?

Posted on by Microsoft Employee

Hi All,

         I need to create case records on CRM from a webapplication. I have already one web application in asp.net which is used by the users., My requirement is like i will add a form in that existing web application which will take the request data from users. Once they submit the form i have to create a new case record in my CRM 2016(onpremise). How to do this. Please share an example if you have.

Thanks

*This post is locked for comments

  • Verified answer
    Faizal Profile Picture
    Faizal 545 on at
    RE: Create Records in CRM using a standalone web application?

    Hi Nidhincee,

    If you are using window authentication, u can follow this for connection.

    public static bool Connect_CRMWindowsAuth()
    {
    ClientCredentials Credentials = new ClientCredentials();

    Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

    Uri OrganizationUri = new Uri(ConfigurationManager.AppSettings["CRMURL"].ToString());

    Uri HomeRealmUri = null;

    Proxy = new OrganizationServiceProxy(OrganizationUri, null, Credentials, null);

    Proxy.EnableProxyTypes();

    Guid currentUserId = Guid.Empty;
    currentUserId = GetUserId(Proxy);
    Proxy.CallerId = currentUserId;

    }

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Create Records in CRM using a standalone web application?

    Refer this:

    stackoverflow.com/.../crm-2011-securitynegotiationexception-trying-to-access-web-services

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Create Records in CRM using a standalone web application?

    Now i am getting this error

    An exception of type 'System.ServiceModel.Security.SecurityNegotiationException' occurred in Microsoft.Xrm.Sdk.dll but was not handled in user code Additional information: The caller was not authenticated by the service.

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Create Records in CRM using a standalone web application?

    Please add the below line in your code just before the connecting to CRM:

    ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };    

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Create Records in CRM using a standalone web application?

    Yes i am connecting CRM using same credentials. And I am running the asp.net application from the CRM server mechine only.

    The dicovery service throws this exception "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Create Records in CRM using a standalone web application?

    unsafe.png

  • Verified answer
    Joe Gill Profile Picture
    Joe Gill on at
    RE: Create Records in CRM using a standalone web application?

    You should not need to touch AD.

    Are you running you asp.net app on premise? Can you connect to CRM using the same credentials?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Create Records in CRM using a standalone web application?

    Dear Faisal & Joe Gill ,

       I created a webform and added the code as you suggested. My CRM is CRM 2106 onpremises. The issue now is the proxyservice does not get authenticated. It says some certification issue.

    crmw2016/.../Discovery.svc

    even the discovery service url is not working in the browser. It shows not secured. I am using my active directory credentials to connect the service and create record. Can you suggest what are the changes i have to do in active directory to make it out?

  • Verified answer
    Faizal Profile Picture
    Faizal 545 on at
    RE: Create Records in CRM using a standalone web application?

    Hi,

    Just high level:

    • Create ASP.Net program and connect to CRM via SDK & Connection string.
    • On page load; necessary aspx form validation.
    • On button send/create/update:
      • Store user entry from aspx to CRM case attribute.
      • Prepare necessary validation in the code to create/update case record.

    example:

    //################################################################################

    protected void Page_Load(object sender, EventArgs e)
    {
    if(fn_ConnectToMicrosoftCRMOnline())
    {
    txtFirstName.Focus();
    if (!Page.IsPostBack)
    {
    DropDownDataBind();
    }
    }
    }

    //###########################################################################################################

    private bool fn_ConnectToMicrosoftCRMOnline()
    {
    bool permission = false;
    if (Convert.ToBoolean(ConfigurationManager.AppSettings["OnlineCRM"].ToString()) == false)
    permission = CommonClass.Connect_CRMWindowsAuth();
    else
    permission = CommonClass.Connect_CRM();

    lvObj_CRMServiceProxy = CommonClass.Proxy;
    return permission;
    }

    //###########################################################################################################

    private void DropDownDataBind()
    {
    ddlGender.DataSource = CommonClass.BindOptionSet("incident", "new_gender");
    ddlGender.DataBind();

    }

    //################################################################################

    protected void Button1_Click(object sender, EventArgs e)
    {
    Page.Validate();
    if (Page.IsValid)
    {

    Mandatory = true;

    Entity Incident= new Entity("incident");

    //Text field.###########
    if (txtFirstName.Text != string.Empty)
    {
    Volunteer.Attributes["new_name"] = txtFirstName.Text;
    lbFirstName.Visible = false;
    }
    else
    {
    lbFirstName.Visible = true;
    lbFirstName.ForeColor = Color.Red;
    lbFirstName.Text = "Missing Mandatory Field";
    Mandatory = false;
    }

    //DropDown.###########
    if (Convert.ToInt32(ddlGender.SelectedIndex) > 0)
    {
    int test = Convert.ToInt32(ddlGender.SelectedValue);
    Volunteer.Attributes["new_gender"] = new OptionSetValue(Convert.ToInt32(ddlGender.SelectedValue));
    }

    // Create Incident based on validation.###########

    if ((CaptchaStatus) && (Mandatory))
    {
    lvObj_CRMServiceProxy.Create(incident).ToString();
    System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AlertBox", "alert('Application submitted successfully.');", true);
    ClearControls(this.Page);
    }

    //################################################################################

  • Suggested answer
    Joe Gill Profile Picture
    Joe Gill on at
    RE: Create Records in CRM using a standalone web application?

    Hi,

    Probably the simplest approach would be do write some code in your ASP.NET app to create the case record similar to the sample https://msdn.microsoft.com/en-us/library/gg328416.aspx

    The alternatives would be either call the CRM WebAPI from Javascript https://community.dynamics.com/crm/b/scaleablesolutionsblog/archive/2016/01/18/web-api-authentication-from-javascript

    or write you own custom Web Api to create the case and call this Web API from your ASP.NET app

    hth

    Joe

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

Featured topics

Product updates

Dynamics 365 release plans