本文介绍了使用C#连接到Salesforce大宗原料药的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图连接到SalesForce.com大宗原料药,所以我可以从我的应用程序做数据质量上传。我已经通过强调使用curl使在POST请求。在与指令一致,我已经创建在其用于登录到服务器的XML格式的文本文件

I am trying to connect to the SalesForce.com bulk API so I can do mass uploads of data from my application. I have read through the PDF documentation which emphasizes using CURL to make the POST requests. In keeping with the instructions, I have created a text file in XML format which is used for logging into the server.

下面的login.txt内容:

Login.txt contents below:

<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
    <env:Body>
     <n1:login xmlns:n1="urn:partner.soap.sforce.com">
            <n1:username>my username</n1:username>
         <n1:password>my password</n1:password>
     </n1:login>
     </env:Body>
</env:Envelope>

下面是我想在我的代码做,使登录请求:

Here is what I'm trying to do in my code to make the login request:

XmlDocument XMLResponse = null;

HttpWebRequest httpRequest;

HttpWebResponse httpResponse = null;

Stream requestStream = null;
Stream responseStream = null;

XmlTextReader xmlReader;

httpRequest = HttpWebRequest)WebRequest.Create("https://login.salesforce.com/services/Soap/c/20.0");

try
{
            byte[] bytes = File.ReadAllBytes(filename);
            httpRequest.Method = "POST";
            httpRequest.ContentLength = bytes.Length;
            httpRequest.ContentType = "text/xml; charset=UTF-8";
            httpRequest.Headers.Add("SOAPAction: login");
            requestStream = httpRequest.GetRequestStream();
            requestStream.Write(bytes, 0, bytes.Length);
            requestStream.Close();

            httpResponse = (HttpWebResponse)httpRequest.GetResponse();

            if (httpResponse.StatusCode == HttpStatusCode.OK)
            {
                responseStream = httpResponse.GetResponseStream();

                xmlReader = new XmlTextReader(responseStream);

                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(xmlReader);

                XMLResponse = xmldoc;
                xmlReader.Close();
            }

            httpResponse.Close();
}

在此代码执行我总是得到一个500错误。有没有人在做什么,我试图做的经验吗?能否请您为我提供一些建议吗?

When this code executes I always get a 500 error. Does anyone have any experience in doing what I am attempting to do? Could you please provide me with some suggestions?

感谢您提前。

推荐答案

对于登录的一部分,只需下载并导入合作伙伴WSDL和使用生成的Web服务客户端。否则,你要更新你的代码读取响应时,得到一个500状态码(SOAP规范要求故障消息使用500状态码),响应主体会给你更多的线索来解决问题。我期望在这种情况下你得到一个身份确认错误,你就需要提供除登录请求您的密码您的API安全令牌。

For the login part, just download and import the partner WSDL and use the generated web service client. Otherwise, you'll want to update your code to read the response when it gets a 500 status code (the SOAP spec requires fault messages to use a 500 status code), the response body will give you more clues to the problem. I'd expect in this case you're getting an identity confirmation error, and you'll need to provide your api security token in addition to your password in the login request.

这篇关于使用C#连接到Salesforce大宗原料药的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 13:36