0

我在http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/d5d00302-8f7b-4efc-873b-c54b3e29749d上问了同样的问题,但没有得到答案。所以,我会在stackoverflow上再试一次。

我正在运行 crm 2011 培训工具包中的示例代码。

 var creds = new ClientCredentials();
 var dsp = new DiscoveryServiceProxy( dinfo, creds);
 dsp.Authenticate();
 var orgRequest = new RetrieveOrganizationRequest();
 var response = dsp.Execute(orgRequest);
 var orgResponse = response as RetrieveOrganizationsResponse;
 if (orgResponse != null)
 comboOrgs.ItemsSource = orgResponse.Details;

在var response = dsp.Execute(orgRequest)这一行,我得到了FaltException`1,详细信息如下

System.ServiceModel.FaultException`1 was unhandled
 Message=organizationName
 Source=mscorlib
 Action=http://schemas.microsoft.com/xrm/2011/Contracts/Discovery/IDiscoveryService/ExecuteDiscoveryServiceFaultFault
 StackTrace:
 Server stack trace: 
 at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
 at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
 at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
 at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
 Exception rethrown at [0]: 
 at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
 at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
 at Microsoft.Xrm.Sdk.Discovery.IDiscoveryService.Execute(DiscoveryRequest request)
 at Microsoft.Xrm.Sdk.Client.DiscoveryServiceProxy.Execute(DiscoveryRequest request)

我能够使用浏览器访问 Discovery.svc 文件。所以服务器 url 应该是正确的。这是身份验证问题吗?

4

1 回答 1

1

这是针对 Microsoft CRM Online 还是内部部署?对于在线,我知道您会想要使用与 SDK 中的内容类似的东西 -

// Connect to the Discovery service. 
// The using statement assures that the service proxy will be properly disposed.
using (DiscoveryServiceProxy _serviceProxy = new DiscoveryServiceProxy(serverConfig.DiscoveryUri,
                                                    serverConfig.HomeRealmUri,
                                                    serverConfig.Credentials,
                                                    serverConfig.DeviceCredentials))
{
    // You can choose to use the interface instead of the proxy.
    IDiscoveryService service = _serviceProxy;

    #region RetrieveOrganizations Message

    // Retrieve details about all organizations discoverable via the
    // Discovery service.
    RetrieveOrganizationsRequest orgsRequest =
        new RetrieveOrganizationsRequest()
        {
            AccessType = EndpointAccessType.Default,
            Release = OrganizationRelease.Current
        };
    RetrieveOrganizationsResponse organizations =
        (RetrieveOrganizationsResponse)service.Execute(orgsRequest);
}

DiscoveryServiceProxy 类有重载,但如果您提供有关您尝试连接的内容的更多详细信息,我认为它会缩小范围。

于 2011-06-16T03:29:33.783 回答