我是 SOAP Web 服务的新手。我想同步两个 Salesforce 实例。为此,我正在使用合作伙伴 WSDL。我已将此 WSDL 安装到我的实例中,并创建了一个自定义类:
public with sharing class ConnectionManager {
private String uName = 'xxx';
private String Password = 'xxx';
private partnerSoapSforceCom.Soap connection{get;set;}
public ConnectionManager() {
connection = new partnerSoapSforceCom.Soap();
partnerSoapSforceCom.LoginResult status = connection.login(uName, Password);
system.debug('status: '+status);
connection.endpoint_x = status.serverUrl;
connection.SessionHeader = new partnerSoapSforceCom.SessionHeader_element();
connection.SessionHeader.sessionId = status.sessionId;
system.debug('connection.outputHttpHeaders_x: '+connection.outputHttpHeaders_x);
//connection.inputHttpHeaders_x.put('Cookie',connection.outputHttpHeaders_x.get('Set-Cookie'));
system.debug('qr: '+connection.query('SELECT Id, Name FROM Account where Name=\'test\''));
}}
但它给了我一个例外:
System.CalloutException:Web 服务标注失败:无法解析标注响应。未找到元素名称的顶点类型
Class.partnerSoapSforceCom.Soap.query:第 2048 行,第 1 列 Class.ConnectionManager.:第 16 行,第 1 列
它正在登录salesforce,但在“connection.query()”方法中给了我错误。
我检查了调试日志并得到了这个响应 xml:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sf="urn:sobject.partner.soap.sforce.com">
<soapenv:Header>
<LimitInfoHeader>
<limitInfo>
<current>1</current>
<limit>5000</limit>
<type>API REQUESTS</type>
</limitInfo>
</LimitInfoHeader>
</soapenv:Header>
<soapenv:Body>
<queryResponse>
<result xsi:type="QueryResult">
<done>true</done>
<queryLocator xsi:nil="true"/>
<records xsi:type="sf:sObject">
<sf:type>Account</sf:type>
<sf:Id>0019000000lhRWKAA2</sf:Id>
<sf:Id>0019000000lhRWKAA2</sf:Id>
<sf:Name>test</sf:Name>
</records>
<size>1</size>
</result>
</queryResponse>
</soapenv:Body>
</soapenv:Envelope>
请帮我。提前致谢。