Asked by:
How to integrate crm 2013 with asp.net page

Question
-
Hi,
I want to create contact through asp.net application.
I added organization service as a service reference
here is my code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk.Client;
using System.Net;
using Microsoft.Xrm.Sdk;
using System.ServiceModel;
using System.IdentityModel;
using System.Web.SessionState;
public partial class register : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnLogin_Click(object sender, EventArgs e)
{
{
try
{
//Authenticate using credentials of the logged in user;
ClientCredentials Credentials = new ClientCredentials();
Credentials.UserName.UserName = "web.agent";
Credentials.UserName.Password = "pass@word1";
// Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
//This URL needs to be updated to match the servername and Organization for the environment.
Uri OrganizationUri = new Uri("http://mozzo:5555/MozzoLab/XRMServices/2011/Organization.svc");
Uri HomeRealmUri = null;
//OrganizationServiceProxy serviceProxy;
using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null))
{
IOrganizationService service = (IOrganizationService)serviceProxy;
//Instantiate the contact object and populate the attributes.
Entity contact = new Entity("contact");
contact["FirstName"] = txtFirstName.Text.ToString();
contact["LastName"] = txtLastName.Text.ToString();
contact["FullName"] = txtFirstName.Text.ToString() + " " + txtLastName.Text.ToString();
contact["new_UserName"] = txtUsername.Text.ToString();
contact["new_Password"] = txtPassword.Text.ToString();
Guid newContactId = service.Create(contact);
//This code will clear the textboxes after the contact is created.
txtFirstName.Text = "";
txtLastName.Text = "";
txtPassword.Text = "";
txtReEnterPassword.Text = "";
string message = "Data Saved Successfully.";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload=function(){");
sb.Append("alert('");
sb.Append(message);
sb.Append("')};");
sb.Append("</script>");
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString());
}
}
catch (Exception)
{
txtFirstName.Text = "";
txtLastName.Text = "";
txtPassword.Text = "";
txtReEnterPassword.Text = "";
string message = "Please Try Again.";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload=function(){");
sb.Append("alert('");
sb.Append(message);
sb.Append("')};");
sb.Append("</script>");
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString());
}
// Session["login"] = 1;
}
}
}Tuesday, April 22, 2014 8:42 AM
All replies
-
When I run my code I got an error
here is an image
Please help me to resolve this issue
Tuesday, April 22, 2014 8:52 AM -
What type of credentials you have on your application pool?Tuesday, April 22, 2014 9:17 AM
-
crm 2013 install in local machine and credentials are same as machine's user and password
but asp.net page is not connecting with crm. kindly tell me what should I do
Tuesday, April 22, 2014 9:22 AM -
Just according to error message above, this is relevant to the issue that directory listing is denied, the Web site does not have the Directory Browsing feature enabled, and the default document is not configured. You can follow the KB article to resolve this issue.
Tuesday, April 22, 2014 9:27 AM -
I have an entity "account" and its attributes are "new_username" and "new_password". Now I want to retrieve "new_password" where new_username ==abc
tell me how can i retrieve record by query expression and save them into variable
- Proposed as answer by REGHIMA Sofiene Friday, May 2, 2014 8:48 AM
- Unproposed as answer by REGHIMA Sofiene Friday, May 2, 2014 8:48 AM
Tuesday, April 22, 2014 11:06 AM -
using late bound entities :
(but you can also use early bound with a context - similar to the DP of EF)
List<Xrm.SalesOrder> AllOrders = new List<Xrm.SalesOrder>(); QueryExpression qe = new QueryExpression(); qe.EntityName = "salesorder"; qe.ColumnSet = new ColumnSet(true); EntityCollection collection = service.RetrieveMultiple(qe); foreach (Xrm.SalesOrder e in collection.Entities) { AllOrders.Add(e); }
Friday, May 2, 2014 8:52 AM -
The URL you are requesting appears to be a directory. Do you have a default page set up for the application in IIS? In the alternative, request the actual .aspx page in the URL.Friday, May 2, 2014 7:49 PM