使用 C# 访问 Salesforce Webservice API
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1531678/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Accessing Salesforce Webservice API using C#
提问by Max
I havent worked with that Salesforce API before, so I am a bit stuck on how to connect to the salesforce service.
我之前没有使用过那个 Salesforce API,所以我对如何连接到 Salesforce 服务有点困惑。
So far I understood that I have to generate a wsdl file for my account or rather the account of my customer (step 1). So far, so good.
到目前为止,我知道我必须为我的帐户或客户的帐户生成一个 wsdl 文件(步骤 1)。到现在为止还挺好。
But now the Quickstart (http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_quickstart_steps.htm) says something about "Import the WSDL File into your development platform" (step 2).
但是现在 Quickstart ( http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_quickstart_steps.htm) 说明了“将 WSDL 文件导入您的开发平台”(第 2 步)。
How do I import a wsdl file into Visual Studio 2008? I cant find the "Add Web Reference" option which is mentioned in the quickstart.
如何将 wsdl 文件导入 Visual Studio 2008?我找不到快速入门中提到的“添加 Web 参考”选项。
And if I only need to use the WSDL, what use has the Salesforce Dotnet API package which can be downloaded from the salesforce website (http://wiki.developerforce.com/index.php/Salesforce_Dotnet_API)?
如果我只需要使用 WSDL,那么可以从 Salesforce 网站 ( http://wiki.developerforce.com/index.php/Salesforce_Dotnet_API)下载的 Salesforce Dotnet API 包有什么用?
Are there any gotchas I should watch out for when developing applications that use the salesforce API?
在开发使用 salesforce API 的应用程序时,我应该注意哪些问题?
采纳答案by Adam Butler
If you follow the directions in Binz' answer, you should be able to add a web service reference using Visual Studio.
如果您按照 Binz 的回答中的说明进行操作,您应该能够使用 Visual Studio 添加 Web 服务引用。
The "Salesforce Dotnet API package" on the wiki site is not required to access the SalesForce API, it's just a library that tries to abstract it.
wiki 站点上的“Salesforce Dotnet API 包”不需要访问 SalesForce API,它只是一个尝试对其进行抽象的库。
As far as gotchas and other things to know, I would recommend that you read chapter 6 of the Force.com Cookbook. You have to sign up for a force.com developer account (free). Most of the things you'll need to be aware of are covered in this chapter. Here are a few of them:
至于陷阱和其他要知道的事情,我建议您阅读Force.com Cookbook 的第 6 章。您必须注册 force.com 开发者帐户(免费)。您需要了解的大部分内容都包含在本章中。这里有几个:
- logging in / logging out - session management
- query / queryMore pattern (needed if you're going to pull large sets of data from SalesForce)
- how to construct a wrapper class - there is some sample vb.net code you can download as well
- 登录/注销 - 会话管理
- query / queryMore 模式(如果您要从 SalesForce 提取大量数据,则需要此模式)
- 如何构建包装类 - 您也可以下载一些示例 vb.net 代码
One other thing to note, if you're going to use SOQL to query your SalesForce data, and you need to filter on a SalesForce date field, you'll need to format the date string. Here's one way to do it:
另一件需要注意的事情是,如果您打算使用 SOQL 查询您的 SalesForce 数据,并且您需要过滤 SalesForce 日期字段,您将需要格式化日期字符串。这是一种方法:
public static string FormatDateForQuery(DateTime dateToFormat, bool includeTime)
{
if (includeTime)
{
return dateToFormat.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss+00:00");
}
else
{
return dateToFormat.ToUniversalTime().ToString("yyyy-MM-dd");
}
}
回答by Binz
For Visual Studio 2008 you need to select 'Add Service Reference', then click the 'Advanced' button on the bottom left of the dialogue. There should then be a button on the bottom of that dialogue that says 'Add Web Reference'. You should be able to then select your wsdl file and a service client proxy will be auto genned for you by VS.
对于 Visual Studio 2008,您需要选择“添加服务引用”,然后单击对话框左下方的“高级”按钮。然后该对话框底部应该有一个按钮,上面写着“添加 Web 引用”。然后您应该能够选择您的 wsdl 文件,并且 VS 将为您自动生成服务客户端代理。
回答by Alex
There is a parsing issue when using .NET 2.0 with date time fields in salesforce, accessing through web services.
在 salesforce 中使用带有日期时间字段的 .NET 2.0 时存在解析问题,通过 Web 服务进行访问。
It seems to be a bug in .NET but there's another way to address it by manually editing the wsdl.
这似乎是 .NET 中的一个错误,但还有另一种方法可以通过手动编辑 wsdl 来解决它。
More information here:
更多信息在这里:
回答by Joseph Anderson
To create the WSDL file, go to (your name, top right), set up, develop > api > generate enterprise wsdl > generate. In Chrome, click save page as and put that file in the c drive. In Visual Studio, go to add service reference > advanced > add web reference. Point to the file you downloaded: file:///c:/wsdl.jsp.xml
要创建 WSDL 文件,请转到(您的姓名,右上角),设置、开发 > api > 生成企业 wsdl > 生成。在 Chrome 中,单击将页面另存为并将该文件放在 c 驱动器中。在 Visual Studio 中,转到添加服务引用 > 高级 > 添加 Web 引用。指向您下载的文件:file:///c:/wsdl.jsp.xml