如何替換和擴展此代碼以在認證憑證中使用密碼和用戶名。我試圖通過分析mscrm sdk中的示例來解決這個問題,但沒有運氣,因爲我不是c#程序員。如何使用用戶名和密碼連接到mscrm?
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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void id_Click(object sender, EventArgs e)
{
AuthenticationCredentials authCredentials = new AuthenticationCredentials();
//Authenticate using credentials of the logged in user;
ClientCredentials Credentials = new ClientCredentials();
Uri OrganizationUri = new Uri("http://Crm/Contoso/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();
Guid newContactId = service.Create(contact);
}
}
}
謝謝!