我想調用salesforce web服務,但出現此錯誤:在System.dll中出現未處理的類型爲「System.Net.WebException」的異常和其他信息:錯誤en el servidor遠端:(500)錯誤interno del servidor。從控制檯應用程序c調用Web服務#
但是當我用Java調用相同的Web服務時,我不會收到任何錯誤。
這是我使用的C#代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static String ST = "some_string";
static String pwd = "password";
static String userName = "myusername";
static String SERVER_URL;
static String SESSION_ID;
static void Main(string[] args)
{
string url = " https://test.salesforce.com/services/Soap/u/30.0";
string details = CallRestMethod(url);
}
public static string CallRestMethod(string url)
{
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);
webrequest.Method = "POST";
webrequest.ContentType = "text/xml;charset=UTF-8";
webrequest.Headers.Add("SOAPAction", "\"\"");
String input = "<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\"><Header/><Body><login xmlns=\"urn:partner.soap.sforce.com\"><username>" + userName + "</username><password>" + pwd + ST + "</password></login></Body></Envelope>";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] byte1 = encoding.GetBytes(input);
webrequest.GetRequestStream().Write(byte1, 0, byte1.Length);
/*Stream newStream = webrequest.GetRequestStream();
newStream.Write(byte1, 0, byte1.Length);
newStream.Close();*/
Console.WriteLine(webrequest.Headers);
HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse();
Encoding enc = System.Text.Encoding.GetEncoding("utf-8");
StreamReader responseStream = new StreamReader(webresponse.GetResponseStream(), enc);
string result = string.Empty;
result = responseStream.ReadToEnd();
webresponse.Close();
return result;
}
}
}
我不想使用wsdl,因爲我想要使用自定義休息方法。 –
然後,您將需要提供REST方法的更多詳細信息。它是否期待SOAP信封XML作爲輸入?你可以用剩餘的客戶端調用方法嗎? –
我想用soap方法登錄並使用rest方法插入數據,我可以用java編寫它,但是當我嘗試使用c#時出現錯誤,我認爲它是https協議。 –