Export (0) Print
Expand All

Accessing the Server Using the Web Service

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Methods are called by first creating an instance of the Web service. In Microsoft Visual Studio 2005, Microsoft IntelliSense support is provided on the Web service methods. To access the server, you may need to specify the URL as shown here for the CrmService.

Example

The following is a simple example accessing the Web service. For a complete set of samples for different authentication scenarios, see Web Service Security and Impersonation.

// Set up the CRM Service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0; 
token.OrganizationName = "AdventureWorksCycle";
 
CrmService service = new CrmService();
service.Url = ""http://<servername>[:<port>]/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

The Web references to the Microsoft Dynamics CRM Web services define a default value for the service's URL property. These default URL values contain the Web service addresses for the Microsoft Dynamics CRM server that was used when you created the Web references. If you need to point your application at a different Microsoft Dynamics CRM server at run time, you must set the CrmService.Url property to the address of the Web services on that server.

Note   As a best practice, you can store the URL of the Microsoft Dynamics CRM server in the application configuration file for your custom code.

If you wish to run your code against a Microsoft Dynamics CRM server on a different domain, you cannot use the default network credentials. You must define valid domain credentials for the domain that has Microsoft Dynamics CRM access rights. Alternatively, you can establish a trust between the two domains.

Important   You must assign a CrmAuthenticationToken value to the Microsoft Dynamics CRM Web service instance before calling Web service methods. Failure to do so results in an HTTP 401 error when the Web service methods are called.

For information about using the backward compatible 2006 endpoint, see Upgrading from Microsoft Dynamics CRM 3.0.

See Also

Other Resources


© 2010 Microsoft Corporation. All rights reserved.


Show:
© 2014 Microsoft