DiscoveryService help needed RRS feed

  • Question

  • Okay, I looked around on the internet and from what I think I understand about M$ CRM you have to have a DiscoveryService. This is how I have my method that calls M$ CRM setup:


    Code Snippet

    protected void SendToCRM(string documentBody)


    string orgName = String.Empty;

    // setup the discovery service

    CrmDiscoveryService crmDiscoveryService = new CrmDiscoveryService();

    crmDiscoveryService.UseDefaultCredentials = true;

    crmDiscoveryService.Url = ConfigurationManager.AppSettings["discoveryServicePath"];

    // retrieve the organization name and endpoint Url from the rmDiscoveryService web service

    RetrieveOrganizationsRequest orgRequest = new RetrieveOrganizationsRequest();

    RetrieveOrganizationsResponse orgResponse = (RetrieveOrganizationsResponse)crmDiscoveryService.Execute(orgRequest);

    OrganizationDetail orgInfo = null;

    foreach (OrganizationDetail orgDetail in orgResponse.OrganizationDetails)


    if (orgDetail.OrganizationName.Equals(orgName))


    orgInfo = orgDetail;




    if (orgInfo == null)

    throw new Exception("The organization name is invalid.");

    // create and configure an instance of the CrmService web service

    CrmAuthenticationToken token = new CrmAuthenticationToken();

    token.AuthenticationType = AuthenticationType.AD;

    token.OrganizationName = orgInfo.OrganizationName;

    CrmService crmService = new CrmService();

    crmService.Url = orgInfo.CrmServiceUrl;

    crmService.CrmAuthenticationTokenValue = token;

    crmService.Credentials = new System.Net.NetworkCredential("name", "password");

    // invoke CrmService web service methods

    WhoAmIRequest whoRequest = new WhoAmIRequest();

    WhoAmIResponse whoResponse = (WhoAmIResponse)crmService.Execute(whoRequest);

    // change the url of the CrmService

    //crmService.Url = ConfigurationManager.AppSettings["crmServicePath"];

    // setup the annotation

    annotation anno = new annotation();

    anno.objectid = CrmTypes.CreateLookup("Opportunity", new Guid("3BD650B4-82F5-49F4-9899-004F4A700AB2"));

    anno.mimetype = "application/xml";

    anno.filename = "TestFileName.xml";

    // anno.filesize = 5000;

    anno.documentbody = Convert.ToBase64String(Encoding.UTF8.GetBytes(documentBody));

    anno.objecttypecode = new EntityNameReference("Opportunity");

    anno.subject = "SubjectOfTheAttachment";

    anno.isdocument = new CrmBoolean(true);

    // save the annotation





    What am I doing wrong? I'm still getting the following error:

    Microsoft.Crm.WebServices, Version=, Culture=neutral,
    PublicKeyToken=31bf3856ad364e35' doesn't exist.
    Parameter name:
    Microsoft.Crm.WebServices, Version=, Culture=neutral,

    Monday, August 18, 2008 3:41 PM


  • I figured it out.  You have to add a reference to Microsoft.CRM.WebServices.dll in your custom app.
    Monday, August 18, 2008 8:37 PM

All replies

  • I figured it out.  You have to add a reference to Microsoft.CRM.WebServices.dll in your custom app.
    Monday, August 18, 2008 8:37 PM
  • You could also add the Microsoft.CRM.WebServices.dll file to the GAC (found at C:\windows\assembly).  This saves a little time if you plan on deploying multiple custom apps to the same CRM server.

    Tuesday, December 16, 2008 7:27 PM