none
aspx页面中怎么初始化和调用CRM2011 webService? RRS feed

  • 常规讨论

  •  Uri orgServiceUri = new Uri("http://crm2011:5555/crm/XRMServices/2011/Organization.svc");
          ClientCredentials credentials = new ClientCredentials();
          credentials.Windows.ClientCredential = new System.Net.NetworkCredential(userName, password, domain);
    
          OrganizationServiceProxy service = new OrganizationServiceProxy(orgServiceUri, null, credentials, null);
    
    
    
          WhoAmIRequest request = new WhoAmIRequest();
          WhoAmIResponse response = (WhoAmIResponse)service.Execute(request);
    
    
    执行的时候把这个错误
    
    ”从另一方收到未进行安全处理或安全处理不正确的错误。有关错误代码和详细信息,请参见内部 FaultException。“
    
    怎么解决?
    

    过好今天!
    2011年5月17日 8:34

全部回复

  •  protected virtual ClientCredentials GetUserLogonCredentials()
        {
          ClientCredentials credentials = new ClientCredentials(); ;
          String userName;
          String password;
          String domain;
    
          // An on-premises Microsoft Dynamics CRM server deployment. 
          if (GetServerType(config.DiscoveryUri) == AuthenticationProviderType.ActiveDirectory)
          {
            String[] domainAndUserName;
    
            do
            {
              Console.Write("\nEnter domain\\username: ");
              domainAndUserName = Console.ReadLine().Split('\\');
    
              if (domainAndUserName.Length == 1 && String.IsNullOrWhiteSpace(domainAndUserName[0]))
              {
                return null;
              }
            }
            while (domainAndUserName.Length != 2 || String.IsNullOrWhiteSpace(domainAndUserName[0]) || String.IsNullOrWhiteSpace(domainAndUserName[1]));
    
            domain = domainAndUserName[0];
            userName = domainAndUserName[1];
    
    
            Console.Write("    Enter password: ");
            password = ReadPassword();
    
            credentials.Windows.ClientCredential = new System.Net.NetworkCredential(userName, password, domain);
          }
          // An Microsoft Dynamics CRM Online server deployment. 
          else if (GetServerType(config.DiscoveryUri) == AuthenticationProviderType.LiveId)
          {
            Console.Write("\n Enter Live ID: ");
            userName = Console.ReadLine();
            if (string.IsNullOrWhiteSpace(userName))
            {
              return null;
            }
    
            Console.Write("Enter Password: ");
            password = ReadPassword();
    
            credentials.UserName.UserName = userName;
            credentials.UserName.Password = password;
          }
          // An internet facing (IFD) Microsoft Dynamics CRM server deployment. 
          else if (GetServerType(config.DiscoveryUri) == AuthenticationProviderType.Federation)
          {
            Console.Write("\n Enter username: ");
            userName = Console.ReadLine();
            if (string.IsNullOrWhiteSpace(userName))
            {
              return null;
            }
    
            Console.Write("Enter Password: ");
            password = ReadPassword();
    
            credentials.UserName.UserName = userName;
            credentials.UserName.Password = password;
          }
          else
            return null;
    
          return credentials;
        }
    

    过好今天!
    2011年5月19日 0:01