3

如何使用 C# 创建 Salesforce 元数据连接?提前致谢。

4

2 回答 2

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;
于 2012-07-25T15:13:34.880 回答
0

使用企业 API 的元数据 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);
        }
于 2017-03-30T02:38:15.393 回答