C# 4.0 将salesforce元数据api与C结合使用#
如何使用C#创建salesforce元数据连接? 提前感谢。找到了答案:C# 4.0 将salesforce元数据api与C结合使用#,c#-4.0,salesforce,C# 4.0,Salesforce,如何使用C#创建salesforce元数据连接? 提前感谢。找到了答案: Sforceservice binding = new Sforceservice(); binding.url = <salesforceurl>; LoginResult lr = binding.login(<username>, <password>); binding.url = lr.serverurl; binding.sesionheadervalue = new se
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;
Sforceservice绑定=新的Sforceservice();
binding.url=;
LoginResult lr=binding.login(,);
binding.url=lr.serverurl;
binding.sesionheadervalue=新sessionheader();
binding.sessionheadervalue.sessionid=lr.sessionid;
MetaDataService服务=新的MetaDataService();
service.sesionheadervalue=新会话头();
service.sessionheadervalue.sessionid=binding.sessionid;
使用企业API的元数据API示例。诀窍是使用企业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);
}