使用属性和节点协助PHP Soap请求
编辑,请参阅我的最后一条评论。我对将全名添加到元数据数组的代码进行了注释 我在使用PHP Soap客户端创建以下XML Soap请求时遇到问题。我遇到的问题是将fullName元素作为子节点添加到sObjects使用属性和节点协助PHP Soap请求,php,xml,soap,xml-parsing,salesforce,Php,Xml,Soap,Xml Parsing,Salesforce,编辑,请参阅我的最后一条评论。我对将全名添加到元数据数组的代码进行了注释 我在使用PHP Soap客户端创建以下XML Soap请求时遇到问题。我遇到的问题是将fullName元素作为子节点添加到sObjects <?xml version="1.0" encoding="UTF-8"?> <x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn1="urn:tooling.soap.sf
<?xml version="1.0" encoding="UTF-8"?>
<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn1="urn:tooling.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<x:Header>
<urn1:SessionHeader>
<urn1:sessionId>a sessionid</urn1:sessionId>
</urn1:SessionHeader>
<urn1:MetadataWarningsHeader>
<urn1:ignoreSaveWarnings>false</urn1:ignoreSaveWarnings>
</urn1:MetadataWarningsHeader>
<urn1:AllOrNoneHeader>
<urn1:allOrNone>false</urn1:allOrNone>
</urn1:AllOrNoneHeader>
<urn1:CallOptions>
<urn1:client/>
</urn1:CallOptions>
</x:Header>
<x:Body>
<urn1:create>
<urn1:sObjects xsi:type="WorkflowFieldUpdate">
<fullName>Lead.Tooling</fullName>
<metadata>
<field>Test_Field_Update__c</field>
<name>Tooling</name>
<notifyAssignee>false</notifyAssignee>
<operation>Null</operation>
<protected>false</protected>
</metadata>
</urn1:sObjects>
</urn1:create>
</x:Body>
我试着把sObject Soapvar改成这个,但没有成功。我不太相信它会起作用
$sObject = new SoapVar(array($fullName, $metadataList), SOAP_ENC_OBJECT, 'WorkflowFieldUpdate', null, 'sObjects')
下面是正确的完整代码。请参阅代码中的注释以获取修复。稍后我将为soap客户端和不同的Sobject添加一个类
<?php
ini_set('display_errors', true);
ini_set("soap.wsdl_cache_enabled", "0");
error_reporting(-1);
$ReturnArray = null;
try {
if (isset($_REQUEST['sessionId']) && isset($_REQUEST['serverUrl'])) {
$sessionId = $_REQUEST['sessionId'];
$serverUrl = str_replace('/u/', '/t/',$_REQUEST['serverUrl']);
$namespace = 'urn:tooling.soap.sforce.com';
$soapClientArray = array(
'user_agent' => 'salesforce-toolkit-php/35.0',
'encoding' => 'utf-8',
'trace' => 1,
'sessionId' => $sessionId
);
$sessionVar = array(
'sessionId' => new SoapVar($sessionId, XSD_STRING)
);
$headerBody = new SoapVar(
$sessionVar,
SOAP_ENC_OBJECT
);
$session_header = new SoapHeader(
$namespace,
'SessionHeader',
$headerBody,
false
);
$soapClient = new SoapClient('tooling.wsdl.xml', $soapClientArray);
$header_array = array(
$session_header
);
$soapClient->__setSoapHeaders($header_array);
$field = new SoapVar('Test_Field_Update__c', XSD_STRING, null, null,'field', null);
$name = new SoapVar('ToolingSample', XSD_STRING, null, null, 'name', null);
$notifyAssignee = new SoapVar(false, XSD_BOOLEAN, null, null, 'notifyAssignee');
$protected = new SoapVar(false, XSD_BOOLEAN, null, null, 'protected');
$operation = new SoapVar('Null', XSD_STRING, null, null, 'operation');
$fullname = new SoapVar('Lead.ToolingSample', XSD_STRING, null, null, 'fullName', null);
$metadata = new SoapVar(
array(
$field,
$name,
$notifyAssignee,
$protected, $operation
),
SOAP_ENC_OBJECT,
null,
null,
'Metadata'
);
// I needed change this line SoapVar
// $metadataList = new SoapVar(array($metadata), SOAP_ENC_OBJECT);
// Fix: Is adding the fullName var to the $metadata array
$metadataList = SoapVar(
array($metadata, $fullname),
SOAP_ENC_OBJECT
);
$sObject = new SoapVar(
$metadataList,
SOAP_ENC_OBJECT,
'WorkflowFieldUpdate',
null,
'sObjects'
);
$sObjects = new SoapVar(
array($sObject),
SOAP_ENC_OBJECT,
null,
null,
null
);
$response = $soapClient->create(new SoapVar($sObjects, SOAP_ENC_OBJECT));
// You can add anything to this array and it will post
$ReturnArray = array(
'success' => true,
'data' => $response,
);
} else {
$ReturnArray = array(
'success' => false,
'data' => 'Unknown error'
);
}
} catch (Exception $e) {
$ReturnArray = array(
'success' => false,
'data' => $e->getMessage()
);
}
// This will output code in the console where it's easier to interpret
echo $_REQUEST['callback'] . '(' . json_encode($ReturnArray) . ')';
下面是正确的完整代码。请参阅代码中的注释以获取修复。稍后我将为soap客户端和不同的Sobject添加一个类
<?php
ini_set('display_errors', true);
ini_set("soap.wsdl_cache_enabled", "0");
error_reporting(-1);
$ReturnArray = null;
try {
if (isset($_REQUEST['sessionId']) && isset($_REQUEST['serverUrl'])) {
$sessionId = $_REQUEST['sessionId'];
$serverUrl = str_replace('/u/', '/t/',$_REQUEST['serverUrl']);
$namespace = 'urn:tooling.soap.sforce.com';
$soapClientArray = array(
'user_agent' => 'salesforce-toolkit-php/35.0',
'encoding' => 'utf-8',
'trace' => 1,
'sessionId' => $sessionId
);
$sessionVar = array(
'sessionId' => new SoapVar($sessionId, XSD_STRING)
);
$headerBody = new SoapVar(
$sessionVar,
SOAP_ENC_OBJECT
);
$session_header = new SoapHeader(
$namespace,
'SessionHeader',
$headerBody,
false
);
$soapClient = new SoapClient('tooling.wsdl.xml', $soapClientArray);
$header_array = array(
$session_header
);
$soapClient->__setSoapHeaders($header_array);
$field = new SoapVar('Test_Field_Update__c', XSD_STRING, null, null,'field', null);
$name = new SoapVar('ToolingSample', XSD_STRING, null, null, 'name', null);
$notifyAssignee = new SoapVar(false, XSD_BOOLEAN, null, null, 'notifyAssignee');
$protected = new SoapVar(false, XSD_BOOLEAN, null, null, 'protected');
$operation = new SoapVar('Null', XSD_STRING, null, null, 'operation');
$fullname = new SoapVar('Lead.ToolingSample', XSD_STRING, null, null, 'fullName', null);
$metadata = new SoapVar(
array(
$field,
$name,
$notifyAssignee,
$protected, $operation
),
SOAP_ENC_OBJECT,
null,
null,
'Metadata'
);
// I needed change this line SoapVar
// $metadataList = new SoapVar(array($metadata), SOAP_ENC_OBJECT);
// Fix: Is adding the fullName var to the $metadata array
$metadataList = SoapVar(
array($metadata, $fullname),
SOAP_ENC_OBJECT
);
$sObject = new SoapVar(
$metadataList,
SOAP_ENC_OBJECT,
'WorkflowFieldUpdate',
null,
'sObjects'
);
$sObjects = new SoapVar(
array($sObject),
SOAP_ENC_OBJECT,
null,
null,
null
);
$response = $soapClient->create(new SoapVar($sObjects, SOAP_ENC_OBJECT));
// You can add anything to this array and it will post
$ReturnArray = array(
'success' => true,
'data' => $response,
);
} else {
$ReturnArray = array(
'success' => false,
'data' => 'Unknown error'
);
}
} catch (Exception $e) {
$ReturnArray = array(
'success' => false,
'data' => $e->getMessage()
);
}
// This will output code in the console where it's easier to interpret
echo $_REQUEST['callback'] . '(' . json_encode($ReturnArray) . ')';
我明白了。我把$full name放错地方了。我把它添加到这个SoapVar下面$metadataList=新的SoapVar(数组($metadata,$fullname),SOAP\u ENC\u对象);我得到了它。我把$full name放错地方了。我把它添加到这个SoapVar下面$metadataList=新的SoapVar(数组($metadata,$fullname),SOAP\u ENC\u对象);