我已尝试过此代码的几种变体。在调试时我看到它拉动了xml文件,但是我无法填充它来填充我创建的类。我已经阅读了这里的帖子以及网络上的几个例子。我尝试了代理类和其他人。每次我得到答案但我不能填写课程。我也在尝试使用类的枚举时遇到问题。我在编译之前遇到错误,所以我不得不走下面的路线。
我正在使用C#.Net 4.5和Visual Studio 2012以及最新的RestSharp。
注意:我是C#的初学者,你可以告诉我。这是一个自学项目。我的一个客户(我为小型企业提供IT服务)让我可以访问他的Zoho来使用API。
问题:我只需要一个建议或指向正确的方向。
先谢谢你
我的模特:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Zoho.Mapping.Rest
{
public class Potentials
{
public string potentialid { get; set; }
public string smownerid { get; set; }
public string potential_owner { get; set; }
public string amount { get; set; }
public string potential_name { get; set; }
public string closing_date { get; set; }
public string stage { get; set; }
public string next_step { get; set; }
public string lead_source { get; set; }
public string smcreatorid { get; set; }
public string created_by { get; set; }
public string modifiedby { get; set; }
public string modified_by { get; set; }
public string created_time { get; set; }
public string modified_time { get; set; }
public string description { get; set; }
public string contactid { get; set; }
public string contact_name { get; set; }
public string last_activity_time { get; set; }
public string lead_conversion_time { get; set; }
public string sales_cycle_duration { get; set; }
public string overall_sales_duration { get; set; }
public string best_daytime_contact { get; set; }
public string priority { get; set; }
public string services { get; set; }
public string type_of_home { get; set; }
public string home_phone { get; set; }
public string source_description { get; set; }
public string property_name { get; set; }
public string current_mowing_service { get; set; }
public string current_lawn_care_service { get; set; }
public string current_mowing_price { get; set; }
public string current_lawn_care_price { get; set; }
}
}
我的主要方法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zoho.Mapping.App_Code;
using Zoho.Mapping;
using Zoho.Mapping.Rest;
using RestSharp;
namespace testZoho
{
class Program
{
static void Main(string[] args)
{
var userToken = "MyLongTokenNumberHERE";
RestClient client = new RestClient();
client.BaseUrl = "https://crm.zoho.com/crm/private/xml/";
RestRequest request = new RestRequest(Method.GET);
request.Resource = "{module}/{method}";
request.AddParameter("module", "Potentials", ParameterType.UrlSegment);
request.AddParameter("method", "getRecords", ParameterType.UrlSegment);
request.AddParameter("authtoken", userToken);
request.AddParameter("scope", "crmapi");
request.AddParameter("newFormat", "1");
request.AddParameter("selectColumns", "All");
request.RootElement = "Potentials";
//var response = client.Execute<Potentials>(request);
IRestResponse responseListPotentials = client.Execute(request);
var xmlContent = responseListPotentials.Content;
Console.WriteLine(xmlContent);
Console.ReadLine();
}
}
}
ZohoCRM API输出:
<?xml version="1.0" encoding="UTF-8"?>
<response uri="/crm/private/xml/Potentials/getRecords">
<result>
<Potentials>
<row no="1">
<FL val="POTENTIALID">683271000001660139</FL>
<FL val="SMOWNERID">683271000000415037</FL>
<FL val="Potential Owner"><![CDATA[Barbara Figueroa]]></FL>
<FL val="Amount"><![CDATA[0]]></FL>
<FL val="Potential Name"><![CDATA[Sist, Lee and Linda]]></FL>
<FL val="Closing Date"><![CDATA[2013-04-30]]></FL>
<FL val="Stage"><![CDATA[Qualified Meeting set]]></FL>
<FL val="Next Step"><![CDATA[null]]></FL>
<FL val="Lead Source"><![CDATA[Church Bulletin]]></FL>
<FL val="SMCREATORID">683271000000415037</FL>
<FL val="Created By"><![CDATA[Barbara Figueroa]]></FL>
<FL val="MODIFIEDBY">683271000000415025</FL>
<FL val="Modified By"><![CDATA[Barbara Suthard]]></FL>
<FL val="Created Time"><![CDATA[2013-04-16 17:18:24]]></FL><FL val="Modified Time"><![CDATA[2013-04-16 17:37:19]]></FL>
<FL val="Description"><![CDATA[LC, LCL, - Wants a face to face has a lot of lawn work clean up trimming etc.]]></FL><FL val="CONTACTID">683271000001660133</FL>
<FL val="Contact Name"><![CDATA[Lee and Linda Sist]]></FL>
<FL val="Last Activity Time"><![CDATA[2013-04-16 17:37:19]]></FL>
<FL val="Lead Conversion Time"><![CDATA[null]]></FL>
<FL val="Sales Cycle Duration"><![CDATA[14]]></FL>
<FL val="Overall Sales Duration"><![CDATA[14]]></FL>
<FL val="Best Daytime Contact"><![CDATA[Phone (work)]]></FL>
<FL val="Services"><![CDATA[null]]></FL>
<FL val="Priority"><![CDATA[null]]></FL>
<FL val="Type of Home"><![CDATA[Single Family Home]]></FL>
<FL val="Home Phone"><![CDATA[null]]></FL>
<FL val="Source description"><![CDATA[null]]></FL>
<FL val="Property Name"><![CDATA[9757 Copeland Drive, Manassas, VA 20109]]></FL>
<FL val="Current Mowing Service"><![CDATA[None]]></FL>
<FL val="Current Lawn Care Service"><![CDATA[None]]></FL>
<FL val="Current Mowing Price"><![CDATA[0]]></FL>
<FL val="Current Lawn Care Price"><![CDATA[0]]></FL>
</row>
<row no="2">
<FL val="POTENTIALID">683271000001660123</FL>
<FL val="SMOWNERID">683271000000415031</FL>
<FL val="Potential Owner"><![CDATA[Robb Boutelle]]></FL>
<FL val="Amount"><![CDATA[0]]></FL>
<FL val="Potential Name"><![CDATA[Lapetina, Christine]]></FL>
<FL val="Closing Date"><![CDATA[2013-04-30]]></FL>
<FL val="Stage"><![CDATA[Unqualified]]></FL>
<FL val="Next Step"><![CDATA[null]]></FL>
<FL val="Lead Source"><![CDATA[Existing Customer]]></FL>
<FL val="SMCREATORID">683271000000415037</FL>
<FL val="Created By"><![CDATA[Barbara Figueroa]]></FL>
<FL val="MODIFIEDBY">683271000000415037</FL>
<FL val="Modified By"><![CDATA[Barbara Figueroa]]></FL>
<FL val="Created Time"><![CDATA[2013-04-16 15:30:23]]></FL>
<FL val="Modified Time"><![CDATA[2013-04-16 15:30:23]]></FL>
<FL val="Description"><![CDATA[LHS - Does not need an appt but call before going out so that he can unlock the gate. He has a flagstone walkway that needs to be extended and redone]]></FL>
<FL val="CONTACTID">683271000000887054</FL>
<FL val="Contact Name"><![CDATA[Christine Lapetina]]></FL>
<FL val="Last Activity Time"><![CDATA[2013-04-16 15:30:23]]></FL>
<FL val="Lead Conversion Time"><![CDATA[null]]></FL>
<FL val="Sales Cycle Duration"><![CDATA[14]]></FL>
<FL val="Overall Sales Duration"><![CDATA[14]]></FL>
<FL val="Best Daytime Contact"><![CDATA[Home]]></FL>
<FL val="Services"><![CDATA[Leaves]]></FL>
<FL val="Priority"><![CDATA[2]]></FL>
<FL val="Type of Home"><![CDATA[Single Family Home]]></FL>
<FL val="Home Phone"><![CDATA[null]]></FL>
<FL val="Source description"><![CDATA[null]]></FL>
<FL val="Property Name"><![CDATA[4812 Twinbrook Rd, Fairfax, VA 22032-2049]]></FL>
<FL val="Current Mowing Service"><![CDATA[None]]></FL>
<FL val="Current Lawn Care Service"><![CDATA[None]]></FL>
<FL val="Current Mowing Price"><![CDATA[0]]></FL>
<FL val="Current Lawn Care Price"><![CDATA[0]]></FL>
</row>
</Potentials>
</result>
</response>