locked
Unable to connect remote server RRS feed

  • Question

  • Hi all,

     

              I'm trying create new account at crm by using c#. I got sample from ms site. I got this error "unable to connect remote server"

    bool success = false;
    
       try
    
       {
    
        string crmServiceUrl = string.Empty;
    
        string organizationName = "PSO";
    
    
    
        CrmDiscoveryService discoveryService = new CrmDiscoveryService();
    
        discoveryService.Url = String.Format(
    
         "http://{0}:{1}/MSCRMServices/2007/{2}/CrmDiscoveryService.asmx",
    
         "crm-srv-01", "80", "AD");
    
    
    
        discoveryService.UseDefaultCredentials = false;
    
        discoveryService.Credentials = new System.Net.NetworkCredential("administrator", "pass@word1", "crm-srv-01");
    
        // STEP 2: Retrieve the organization name and endpoint Url from the
    
        RetrieveOrganizationsRequest orgRequest = new RetrieveOrganizationsRequest();
    
        RetrieveOrganizationsResponse orgResponse =
    
         (RetrieveOrganizationsResponse)discoveryService.Execute(orgRequest);
    
    
    
        String orgUniqueName = String.Empty;
    
        OrganizationDetail orgInfo = null;
    
    
    
        foreach (OrganizationDetail orgDetail in orgResponse.OrganizationDetails)
    
        {
    
         if (orgDetail.FriendlyName.Equals(organizationName))
    
         {
    
          orgInfo = orgDetail;
    
          orgUniqueName = orgInfo.OrganizationName;
    
          break;
    
         }
    
        }
    
    
    
        if (orgInfo == null)
    
         throw new Exception("The organization name is invalid.");
    
    
    
        // STEP 3: Create and configure an instance of the CrmService Web service.
    
    
    
        CrmAuthenticationToken token = new CrmAuthenticationToken();
    
        token.AuthenticationType = AuthenticationType.AD;
    
        token.OrganizationName = orgUniqueName;
    
    
    
        // Set up the CrmService Web service.
    
        CrmService crmService = new CrmService();
    
        if (crmServiceUrl != String.Empty) crmService.Url = crmServiceUrl;
    
        crmService.UseDefaultCredentials = false;
    
        crmService.Credentials = new System.Net.NetworkCredential("Administrator", "pass@word1", "crm-srv-01");
    
        crmService.CrmAuthenticationTokenValue = token;
    
    
    
       //success = true;
    
       //return success;
    
       //Create the account object.
    
       account account = new account();
    
    
    
       // Set the properties of the account object.
    
       account.name = "Fourth Coffee";
    
       account.address1_line1 = "23 Market St.";
    
       account.address1_city = "Sammamish";
    
       account.address1_stateorprovince = "MT";
    
       account.address1_postalcode = "99999";
    
       account.donotbulkemail = new CrmBoolean();
    
       account.donotbulkemail.Value = true;
    
    
    
       // Create the target object for the request.
    
       TargetCreateAccount target = new TargetCreateAccount();
    
    
    
       // Set the properties of the target object.
    
       target.Account = account;
    
    
    
       // Create the request object.
    
       CreateRequest create = new CreateRequest();
    
    
    
       // Set the properties of the request object.
    
       create.Target = target;
    
    
    
       // Execute the request.
    
       CreateResponse created = (CreateResponse)crmService.Execute(create); this part i got error
    
       }
    
    

    Kindly, please advice to me.

     

    Best Regards,

    Yukon

    Saturday, January 1, 2011 4:15 PM

Answers

  • Hi All,

     

             I solved myself.

    <strong>if (crmServiceUrl != String.Empty) crmService.Url = crmServiceUrl; //I wrong this part!</strong>
    
    if (crmServiceUrl != String.Empty) crmService.Url = <a href="http://crm-srv-01:80/MSCRMServices/2007/CrmService.asmx">http://crm-srv-01:80/MSCRMServices/2007/CrmService.asmx</a>;
    

    Thank for watch my post.

     

    Best Regard,

    Yukon

    Saturday, January 1, 2011 5:13 PM