CRM-2011 die Verbindung zur Organisation.svc auf Basis von C#

CRM-2011-setup mit ADFS und HTTPS. Ich bin versucht, eine Verbindung zu der Organisation.svc von benutzerdefinierten web-Seite, die sitzt auf der gleichen IIS-mit CRM 2011, aber sich als eine andere Website mit diesem code:

OrganizationServiceProxy serviceProxy;
ClientCredentials clientCredentials = new ClientCredentials();
clientCredentials.UserName.UserName = "admin";
clientCredentials.UserName.Password = "pass";

Guid contactId = Guid.Empty;

Uri OrganizationUri = new Uri(String.Format("https://organization.crmdev.com:port/XRMServices/2011/Organization.svc"));

Uri HomeRealmUri = new Uri(String.Format("https://organization.crmdev.com:port/XRMServices/2011/Discovery.svc"));

using (serviceProxy = new OrganizationServiceProxy(OrganizationUri, null, clientCredentials, null))
{
    serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
    IOrganizationService service = (IOrganizationService)serviceProxy; 
    Entity contact = new Entity("contact");
    contact.Attributes["lastname"] = "oi oi";
    contactId = service.Create(contact);
}

Es wird eine Fehlermeldung zurückgegeben:

Einem ungesicherten oder falsch gesicherten Schuld wurde von der anderen Partei. Finden Sie die innere FaultException für den Fehlercode und Details.ID3242: Das Sicherheitstoken konnte nicht authentifiziert oder autorisiert.

und in der Ereignisanzeige sehe ich Fehler:

Account For Which Logon Failed:
    Security ID:        NULL SID
    Account Name:       admin
    Account Domain: 
Failure Reason:     Unknown user name or bad password.

obwohl ich den richtigen Benutzernamen und Passwort..

und wenn ich versuche, Sie zu ersetzen:

using (serviceProxy = new OrganizationServiceProxy(OrganizationUri, null, clientCredentials, null))

mit:

using (serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealUri, clientCredentials, null))

gibt es:

Objektverweis nicht auf eine Instanz eines Objekts.

weil serviceProxy null ist.

InformationsquelleAutor Greg Oks | 2012-08-07

Schreibe einen Kommentar