0

我尝试从以下参考链接http://code.msdn.microsoft.com/Consuming-CRM-REST-Service-ae24a15e实现基于 Java 的 CRM 实现,我执行了这些博客提供的步骤。我将生成的代理文件添加到我的项目中。我在向 CRM 服务器添加新实体时遇到了麻烦,我尝试了下面的代码片段以及我的身份验证详细信息

public class client { 

    /** 
     * @param args 
     */ 
    public static void main(String[] args) { 
    Authenticator a = new Authenticator() { 
            public PasswordAuthentication getPasswordAuthentication() { 
                return (new PasswordAuthentication("username", "password".toCharArray())); 
            } 
        }; 
        // Sets the default Authenticator 
        Authenticator.setDefault(a); 
        System.setProperty("java.protocol.handler.pkgs", "jcifs"); 
        Config.setProperty("jcifs.smb.client.domain", "domainname"); 
        Config.setProperty("jcifs.smb.client.username", "username"); 
        Config.setProperty("jcifs.smb.client.password", "password"); 
        Config.setProperty("jcifs.netbios.hostname","hostname"); 

        String[] arguments = { "http://crmserver/organization/xrmservices/2011/organizationdata.svc/", "c:\\crm" }; 
        Generator.main(arguments); 
    } 
    MicrosoftCrmSdkDataServicesService service = new MicrosoftCrmSdkDataServicesService(); 
    Account act = new Account(); 
    String x = UUID.randomUUID().toString(); 
    act.setAccountId(x); 
    act.setName("Account from oData"); 
    try { 
       service.addEntity(act); 
    }  
    catch (Exception e)  
    { 
        e.printStackTrace(); 
    } 

}

在执行上面的代码段时,我遇到了错误,例如 Bad Request (400) - Can't add entity to this entity set让我有任何解决这些问题的建议。

提前致谢!

4

0 回答 0