在C#中更新Dynamics CRM条目

时间:2015-03-10 10:24:53

标签: c# dynamics-crm-2011

我正在尝试了解如何更新Dynamics CRM中的数据,但我失败了。

private const string Url = "*****/XRMServices/2011/OrganizationData.svc/";
    private const string userName = "username";
    private const string password = "password";
    private readonly HttpClientHandler _handler;
    NetworkCredential credentials = new NetworkCredential(userName, password);
    _handler = new HttpClientHandler { Credentials = credentials };

   public void Put()
    {
        StringContent content = new StringContent("<feed><entry><content><m:properties><d:Address1_Country>NEW VALUE</d:Address1_Country></m:properties></content></entry></feed>");

        using (HttpClient client = new HttpClient(_handler))
        {
            client.PutAsync(Url + "AccountSet(guid'182df667-c4f6-e111-8042-0050568e0828')", content).Result;
        }
    }

我得到的回应是:

response = {StatusCode:415,ReasonPhrase:'Unsupported Media Type',版本:1.1,内容:System.Net.Http.StreamContent,标题: {   DataServiceVersion:1.0;   Persistent-Auth:是的   缓存控制:私有   日期:2015年3月10日星期二,格林威治标准时间10:22:07   服务器:Micr ......

1 个答案:

答案 0 :(得分:2)

您正在尝试使用在CRM网络资源之外无效的OData端点。尝试将SOAP端点用于您的目的: https://msdn.microsoft.com/en-us/library/gg334754.aspx https://msdn.microsoft.com/en-us/library/gg328416.aspx