Salesforce REST Api是否有c#包装器?

Salesforce REST Api是否有c#包装器?,c#,api,rest,salesforce,wrapper,C#,Api,Rest,Salesforce,Wrapper,我想将SalesForce信息集成到.net MVC应用程序中 据我所知,SalesForce网站上的示例都是SOAP,或者有一个SalesForce ADO.NET数据提供程序 谢谢。嗯,据我所知不是这样。不过,这没什么大不了的,这取决于您是想在客户端还是服务器端使用javascript方法(如restapi中所述),还是只需在服务器端使用System.Net.WebRequest 检查 我真的希望有什么东西能解析网络响应 转换为表示返回的SF资源的类,并具有坚实的 错误处理-繁琐的内容:)

我想将SalesForce信息集成到.net MVC应用程序中

据我所知,SalesForce网站上的示例都是SOAP,或者有一个SalesForce ADO.NET数据提供程序


谢谢。

嗯,据我所知不是这样。不过,这没什么大不了的,这取决于您是想在客户端还是服务器端使用javascript方法(如restapi中所述),还是只需在服务器端使用
System.Net.WebRequest

检查

我真的希望有什么东西能解析网络响应 转换为表示返回的SF资源的类,并具有坚实的 错误处理-繁琐的内容:)


这是存在的-它被称为SOAP API:)不过,说真的,如果您正在进行服务器端集成,并且想要类型化生成的类和可靠的错误处理,SOAP就是您的小马。

我使用它来简化调用和反序列化对象,但您仍然必须处理所有Salesforce错误代码。它还内置了一些OAuth功能,但是我使用的版本(大约2个月前)不太支持OAuth 2。这仍然是一件痛苦的事情,但是如果你要获取大量数据,那么它是值得的。

下面是使用密码工作流的示例代码。它获取访问令牌并查询API:

public static string Login()
{
    string responseJsonString = string.Empty;
    StringBuilder str = new StringBuilder();
    str.AppendFormat("{0}?grant_type=password&client_id={1}&client_secret={2}&username={3}&password={4}"
                     , LoginOAuthUrl, ClientID, ClientSecret, ClientUserName, ClientPassword);
    // Request token
    try
    {
        HttpWebRequest request = WebRequest.Create(str.ToString()) as HttpWebRequest;

        if (request != null)
        {
            request.Method = "POST";
            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            {
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    // Get the "access_token" and "instance_url" from the response.
                    // Convert the JSON response into a token object


                    // Here we get the response as a stream.
                    using (StreamReader responseStream = new StreamReader(response.GetResponseStream()))
                    {
                        responseJsonString = responseStream.ReadToEnd();
                        // Deserialize JSON response into an Object.
                        JsonValue value = JsonValue.Parse(responseJsonString);
                        JsonObject responseObject = value as JsonObject;
                        AccessToken = (string)responseObject["access_token"];
                        InstanceUrl = (string)responseObject["instance_url"];
                        return "We have an access token: " + AccessToken + "\n" + "Using instance " + InstanceUrl + "\n\n";
                    }
                }
            }
        }
        return responseJsonString;
    }
    catch (Exception ex)
    {
        throw new Exception(string.Format("Unable to login to salesforce: {0}", str), ex);
    }
}

public static string Query()
{            
    string RequestUrl = InstanceUrl + "/services/data/v28.0/query";
    string queryParam = "q=" + QUERY;
    // Read the REST resources
    string responseJsonString = HttpGet(RequestUrl, queryParam);
    return responseJsonString;
}

public static string HttpGet(string URI, string Parameters)
{
    // Add parameters to the URI
    string requestUri = URI + "?" + Parameters;
    System.Net.WebRequest req = System.Net.WebRequest.Create(requestUri);
    req.Method = "GET";
    req.Headers.Add("Authorization: OAuth " + AccessToken);

    // Do the GET request
    System.Net.WebResponse resp = req.GetResponse();
    if (resp == null) return null;
    System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
    return sr.ReadToEnd().Trim();
}

如果您正在寻找Salesforce的RESTAPI客户端库,请查看

它支持从RESTAPI创建、更新、删除和查询记录

创建

client.Create("Account", 
   new { Name = "name created", Description = "description created" }));
client.Update("Account", "<record id>", 
   new { Description = "description updated" }));
client.Delete("Account", "<ID">);
更新

client.Create("Account", 
   new { Name = "name created", Description = "description created" }));
client.Update("Account", "<record id>", 
   new { Description = "description updated" }));
client.Delete("Account", "<ID">);
client.Update(“帐户”),“”,
新的{Description=“Description updated”});
删除

client.Create("Account", 
   new { Name = "name created", Description = "description created" }));
client.Update("Account", "<record id>", 
   new { Description = "description updated" }));
client.Delete("Account", "<ID">);
client.Delete(“Account”),salesforce提供了一个.NET工具包

“Force.com Toolkit for.NET为.NET开发人员提供了一种使用本机库与Force.com REST API交互的简便方法。”


Enhanced尝试将Salesforce的rest API建模为一组接口。这些接口可以使用Enhanced.HttpClientFactory制作成客户端,也可以使用RestEase手动制作


谢谢你的回答。我将使用it服务器端集成到其他系统中。我真的希望能够将WebResponse解析为表示返回的SF资源的类,并具有可靠的错误处理功能(繁琐的东西:)如果你想要强类型,你应该走WSDL的路,使用web服务。REST本身是一种体系结构思想,而不是一种可以生成通用代码的集合协议,它甚至不要求使用sf restApi使用的JSON,也不包括任何可以解析和创建类的标准化元数据您可以使用/sobjects/
object\u name
/description作为开发过程的一部分来检索元数据,然后为元数据创建类并使用
JavaScriptSerializer.Deserialize
。然而,这听起来确实是一件痛苦的事:)有趣的是,我将看看RestSharp。我正在查看asp.net web api示例,这些示例将扩展到通过OAuth2访问twitter:谢谢你的链接,我一定会去看看。这是OAuth2的示例吗?我没有仔细看,但我注意到了oauth_uuu前缀,它没有在Salesforce OAuth2服务中实现。