如何替换和扩展此代码以在身份验证凭据中使用密码和用户名。我试图通过分析 mscrm sdk 中的示例来解决这个问题,但没有运气,因为我不是 c# 程序员。
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);
}
}
}
谢谢!