Frage

I'm running the following code to access CRM Dynamics DB.

using (OrganizationServiceProxy proxy 
  = new OrganizationServiceProxy(organizationUri, null, credentials, null))
{
  const String request = @"
    <fetch mapping ='logical'>
      <entity name = 'account'>
        <attribute name = 'name'/>
      </entity>
    </fetch>";

    FetchExpression expression = new FetchExpression(request);
    EntityCollection result = proxy.RetrieveMultiple(expression);
    ...
}

I'm fairly sure that organizationUrl and credentials are correct. According to this walk-through, the other two can be set to null for this simple case.

The problem is that when I get to the last line, retrieval to result, I get Exception telling me that:

System.ArgumentNullException was unhandled

Message=Value cannot be null.

Parameter name: CurrentServiceEndpoint

What did I forgot and how do I resolve this problem?

EDIT:

System.ArgumentNullException was unhandled

HResult=-2147467261

Message=Value cannot be null.

Parameter name: CurrentServiceEndpoint

Source=Microsoft.Xrm.Sdk

ParamName=CurrentServiceEndpoint

StackTrace:

at Microsoft.Xrm.Sdk.ClientExceptionHelper.ThrowIfNull(Object parameter, String name)

at Microsoft.Xrm.Sdk.Client.ServiceConfiguration`1.CreateChannelFactory(ClientCredentials clientCredentials)

at Microsoft.Xrm.Sdk.Client.OrganizationServiceConfiguration.CreateChannelFactory(ClientCredentials clientCredentials)

at Microsoft.Xrm.Sdk.Client.ServiceProxy`1.get_ChannelFactory()

at Microsoft.Xrm.Sdk.Client.ServiceProxy`1.CreateNewServiceChannel()

at Microsoft.Xrm.Sdk.Client.ServiceProxy`1.ValidateAuthentication()

at Microsoft.Xrm.Sdk.Client.ServiceProxy`1.get_ServiceChannel()

at Microsoft.Xrm.Sdk.Client.ServiceContextInitializer1.Initialize(ServiceProxy1 proxy)

at Microsoft.Xrm.Sdk.Client.ServiceContextInitializer1..ctor(ServiceProxy1 proxy)

at Microsoft.Xrm.Sdk.Client.OrganizationServiceContextInitializer..ctor(OrganizationServiceProxy proxy)

at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.RetrieveMultipleCore(QueryBase query)

at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.RetrieveMultiple(QueryBase query)

at CRM_Server_Accessor.Program.Main(String[] args) in C:\Users\Viltersten\documents\Software\Projects\CRM_Server_Accessor\Program.cs:line 60

at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)

at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

at System.Threading.ThreadHelper.ThreadStart()

InnerException:

War es hilfreich?

Lösung

Add a Service Reference in your project, pointing to your organization's org service.

URL would be like this: http://yourCRMserver/yourOrganization/XRMServices/2011/Organization.svc

Name it, say, OrganizationService.

Then, in your code you would proceed like this:

using (OrganizationService.OrganizationServiceClient client = new OrganizationService.OrganizationServiceClient())
{
    const String request = "<Your FetchXml query goes here>";
    FetchExpression expression = new FetchExpression(request);
    EntityCollection result = client.RetrieveMultiple(expression);
    //...
}

This MSDN article provides a good sample code about authentication including Online.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top