Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

WEB API REST crm 2016 on premise IFD ERROR

Posted on by 60

Hello,

I need help plz
I wanted to create a web service rest that will connect to the crm

To do this I started with a console application to test the connection to my CRM organization

Here is the example that works

CrmServiceClient conn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient
(@"Url=https://otest.scom.fr/otest; Domain=AB; Username=AB\admin; Password=pass;
 AuthType=IFD;");

IOrganizationService service = (IOrganizationService)conn.OrganizationServiceProxy;
        Entity _contact = new Entity("contact");
        _contact.Attributes["firstname"] = "jan";
_contact.Attributes["lastname"] = "ban";
Guid contactId = service.Create(_contact);

So I used the same code to make my rest api , But it does not work

public class CRMController : ApiController
    {
        
        // GET: api/CRM
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET: api/CRM/5
        public string Get(int id)
        {
            CrmServiceClient conn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient
(@"Url=https://otest.scom.fr/otest; Domain=AB; Username=AB\admin; Password=pass;
 AuthType=IFD;");

IOrganizationService service = (IOrganizationService)conn.OrganizationServiceProxy;
            Entity _contact = new Entity("contact");
            _contact.Attributes["firstname"] = "jan";
            _contact.Attributes["lastname"] = "ban";
            Guid contactId = service.Create(_contact);
            return contactId.ToString();
        }

        // POST: api/CRM
        public void Post([FromBody]string value)
        {
        }

        // PUT: api/CRM/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE: api/CRM/5
        public void Delete(int id)
        {
        }
    }

2017_2D00_03_2D00_24_5F00_15h08_5F00_42.png

and service = null;

2017_2D00_03_2D00_24_5F00_15h13_5F00_47.png

*This post is locked for comments

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans