我希望将SalesForce信息集成到.net MVC应用程序中。
据我所知,SalesForce网站上的样例都是SOAP,或者可以使用SalesForce ADO.NET数据提供程序。
http://wiki.developerforce.com/page/Web_Services_API#.NET
谢谢。
我希望将SalesForce信息集成到.net MVC应用程序中。
据我所知,SalesForce网站上的样例都是SOAP,或者可以使用SalesForce ADO.NET数据提供程序。
http://wiki.developerforce.com/page/Web_Services_API#.NET
谢谢。
销售力公司宣布推出了一个.NET工具包。
"Force.com Toolkit for .NET为.NET开发人员提供了一种使用本地库与Force.com REST API进行交互的简单方法。"
https://github.com/developerforce/Force.com-Toolkit-for-NET/
client.Create("Account",
new { Name = "name created", Description = "description created" }));
更新
client.Update("Account", "<record id>",
new { Description = "description updated" }));
删除
client.Delete("Account", "<ID">);
查询
var records = client.Query<Account>("SELECT id, name, description FROM Account");
我使用RestSharp来简化调用并反序列化对象,但您仍然需要处理所有销售引擎的错误代码。它还内置了一些OAuth功能,但我使用的版本(大约2个月前)对OAuth 2支持不是很好。虽然有点麻烦,但如果您要拉取大量数据,则非常值得。
嗯,据我所知没有。不过,具体取决于你想要在客户端还是服务器端使用它,你可以使用文档化的javascript方法(如restapi),或者在服务器端简单地使用System.Net.WebRequest
。
请查看Dan的.NET博客
/sobjects/
object_name/describe
来检索元数据,然后为其创建类并使用JavaScriptSerializer.Deserialize<T>
。然而,这听起来真的很麻烦 :) - mmix这是使用密码工作流的示例代码。它获取访问令牌并查询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的rest API建模的尝试,将其建模为一组接口。这些接口可以使用Reinforce.HttpClientFactory或手动使用RestEase转换为客户端。