views:

105

answers:

2

I am running this code (with names and security details obscured). When I do, I get 401 unauthorised. The credentials are that of the user on the hosted server. Is this possible against an IFD system?

var token = new CrmAuthenticationToken(); token.AuthenticationType = 0; token.OrganizationName = "myorganisation";

    CrmService service = new CrmService();
    service.Url = "https://myorganisation.dynamicsgateway.com/mscrmservices/2007/crmservice.asmx";
    service.CrmAuthenticationTokenValue = token;
    service.Credentials = new NetworkCredential("bob.smith", "Password", "HOSTEDCRM");

    var request = new RetrieveMultipleRequest();
    request.Query = new QueryExpression
    {
        ColumnSet = new ColumnSet(new string[] { "name" }),
        EntityName = "account"
    };
    var response = service.Execute(request);
+1  A: 

Yes, it's possible, you are only missing a little pieces, the CrmAuthenticationToken.ExtractCrmAuthenticationToken.

Check out this great explaination on Dynamics Forum http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/81f8ba82-981d-40dd-893d-3add67436478

Mercure Integration
That looks good but how do I get a link to the disco service? Visual studio sees the XML but won't add the link saying the dicovery information isn't available.
Bill Jeeves
The Disco Service is always at /MSCRMServices/2007/SPLA/CrmDiscoveryService.asmx under the current URL. You don't want to add a reference to it, because all pages under the ISV directory runs on their own, they run under the CRM Application Pool so you can't add references to services.
Mercure Integration
BTW, just in case that you created an Application for your ASPx pages, you can't use that with IFD, you must drop ASPx pages under the ISV folder so that they can be compiled by the CRM application and integrated in the same context...
Mercure Integration
+1  A: 

I assume this code is outside of the CRM Website? In that case you'll want to add a reference to the discovery service as Mercure points out above. You'll want to execute a RetrieveCrmTicketRequest against the discovery service to get a ticket good for connecting to the Crm Services.

In your CRM Authentication Token you'll want to set the authentication type to 2 (IFD). Then set the CrmTicket property on the token to the ticket you got from your RetrieveCrmTicketResponse.

I also set the URL based on that response, but you could continue to hard code it.

You will want to continue to set the Credentials on the service.

I use a single user to connect to CRM and cache that ticket (an expiration date is in the response from the discovery service). That way I can bypass the discovery service on future requests. There is an error code to look for to go after the ticket again, but I don't have it off hand.

benjynito