如何使用C#创建salesforce元数据连接? 提前谢谢。
答案 0 :(得分:3)
找到答案:
Sforceservice binding = new Sforceservice();
binding.url = <salesforceurl>;
LoginResult lr = binding.login(<username>, <password>);
binding.url = lr.serverurl;
binding.sesionheadervalue = new sessionheader();
binding.sessionheadervalue.sessionid = lr.sessionid;
MetaDataService service = new MetaDataService();
service.sesionheadervalue = new sessionheader();
service.sessionheadervalue.sessionid = binding.sessionid;
答案 1 :(得分:0)
使用Enterprise API的Metadata API示例。 技巧是使用Enterprise API将登录会话标头更改为MetaAPI客户端
string username = "username";
string password = "password";
// Create a SoapClient specifically for logging in
loginClient = new SoapClient();
LoginResult lr = null;
try
{
Console.WriteLine("\nLogging in...\n");
lr = loginClient.login(null, username, password);
}
catch (Exception e)
{
// Write the fault message to the console
Console.WriteLine("An unexpected error has occurred: " + e.Message);
// Write the stack trace to the console
Console.WriteLine(e.StackTrace);
}
// Check if the password has expired
if (lr.passwordExpired)
{
Console.WriteLine("An error has occurred. Your password has expired.");
}
// end point
endpoint = new EndpointAddress(lr.metadataServerUrl);
Console.WriteLine("End point: " + endpoint.Uri);
// session header
Metadata.SessionHeader metaSession = new Metadata.SessionHeader();
metaSession.sessionId = lr.sessionId;
MetadataPortTypeClient client = new MetadataPortTypeClient("Metadata", endpoint);
CallOptions callOptions = new CallOptions();
callOptions.client = lr.userId;
ListMetadataQuery q = new ListMetadataQuery();
q.type = "CustomObject";
FileProperties[] fs = client.listMetadata(metaSession, callOptions, new []{ q} , 39.0);
foreach (FileProperties f in fs)
{
Console.WriteLine("response with message: " + f.fileName);
Console.WriteLine("response with message: " + f.fullName);
}