I am trying to connect vs to crm..Though my client credentials are correct..It is not taking those values...I am getting exception as The caller was not authenticated by the service..This is my code..can any one help me out..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Discovery;
using Microsoft.Xrm.Sdk.Query;
namespace crmtowindowwww
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
try
{
ClientCredentials cre1 = new ClientCredentials();
cre1.UserName.UserName = "username ";
cre1.UserName.Password = "passowrd" ;
Uri serviceUri = new Uri("organization uri");
OrganizationServiceProxy proxy = new OrganizationServiceProxy(serviceUri,null,cre1,null);
proxy.EnableProxyTypes();
IOrganizationService service = (IOrganizationService)proxy;
Entity ent = new Entity("contact");// creation of entity
ent.Attributes["firstname"] = textBox1.Text;
ent.Attributes["lastname"] = textBox2.Text;
service.Create(ent);
}
catch (Exception ex)
{
throw new InvalidOperationException();
}
}
}
}