CRM 2011 Dicovery服务FaultException

时间:2011-06-15 23:11:22

标签: crm dynamics-crm-2011

我在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应该是正确的。这是身份验证问题吗?

1 个答案:

答案 0 :(得分: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类存在重载,但如果您提供有关您尝试连接的内容的更多详细信息,我认为它会缩小范围。