问题描述
以下是我构造肥皂请求的代码.我可以创建一个客户端,但是要更新客户端,我需要客户端编号作为客户端标签中的属性.
Below is my code to construct the soap request. I can create a client, but to update a client, I need the client number as an attribute in the client tag.
$urn = '<SOME DEFINITION>';
$urn1 = '<SOME DEFINITION>';
$urn2 = '<SOME DEFINITION>';
// Main descriptive content of the client
$clientType = $clientInfo['clt_type'];
$companyName = $clientInfo['clt_name'];
$mainPaymentMethod = '0001';
$mainPaymentCondition = '0003';
/* Build sales portion */
$sales_city = $clientInfo['clt_sales_city'];
$sales_area1 = $clientInfo['clt_sales_state'];
$sales_zipCode = $clientInfo['clt_sales_zipcode'];
$sales_countryCode = $clientInfo['clt_sales_country'];
$sales_address = $clientInfo['clt_sales_address'];
$sales_address_two = $clientInfo['clt_sales_address2'];
$salesGeneralFitness = 'MAIN';
$salesBillingFitness = 'MAIN';
$salesAddressParams[] = new SoapVar($sales_address, XSD_STRING, null, $urn1, 'Address', $urn1);
$salesAddressParams[] = new SoapVar($sales_address_two, XSD_STRING, null, $urn1, 'AddressComplement', $urn1);
$salesAddressParams[] = new SoapVar($sales_zipCode, XSD_STRING, null, $urn1, 'ZipCode', $urn1);
$salesAddressParams[] = new SoapVar($sales_city, XSD_STRING, null, $urn1, 'City', $urn1);
$salesAddressParams[] = new SoapVar($salesGeneralFitness, XSD_STRING, null, $urn2, 'GeneralFitness', $urn2);
$salesAddressParams[] = new SoapVar($salesBillingFitness, XSD_STRING, null, $urn2, 'BillingFitness', $urn2);
$salesAddressParams[] = new SoapVar($sales_area1, XSD_STRING, null, $urn2, 'Area1', $urn2);
$salesAddressParams[] = new SoapVar($sales_countryCode, XSD_STRING, null, $urn2, 'CountryCode', $urn2);
$SalesAddress = new SoapVar($salesAddressParams, SOAP_ENC_OBJECT, null, $urn2, 'Address', $urn2);
/* End of sales portion */
/* Build financial portion */
$financial_city = $clientInfo['clt_financial_city'];
$financial_area1 = $clientInfo['clt_financial_state'];
$financial_zipCode = $clientInfo['clt_financial_zipcode'];
$financial_countryCode = $clientInfo['clt_financial_country'];
$financial_address = $clientInfo['clt_financial_address'];
$financial_address_two = $clientInfo['clt_financial_address2'];
$financialGeneralFitness = 'MAIN';
$financialBillingFitness = 'MAIN';
$financialAddressParams[] = new SoapVar($financial_address, XSD_STRING, null, $urn1, 'Address', $urn1);
$financialAddressParams[] = new SoapVar($financial_address_two, XSD_STRING, null, $urn1, 'AddressComplement', $urn1);
$financialAddressParams[] = new SoapVar($financial_zipCode, XSD_STRING, null, $urn1, 'ZipCode', $urn1);
$financialAddressParams[] = new SoapVar($financial_city, XSD_STRING, null, $urn1, 'City', $urn1);
$financialAddressParams[] = new SoapVar($financialGeneralFitness, XSD_STRING, null, $urn2, 'GeneralFitness', $urn2);
$financialAddressParams[] = new SoapVar($financialBillingFitness, XSD_STRING, null, $urn2, 'BillingFitness', $urn2);
$financialAddressParams[] = new SoapVar($financial_area1, XSD_STRING, null, $urn2, 'Area1', $urn2);
$financialAddressParams[] = new SoapVar($financial_countryCode, XSD_STRING, null, $urn2, 'CountryCode', $urn2);
$FinancialAddress = new SoapVar($financialAddressParams, SOAP_ENC_OBJECT, null, $urn2, 'Address', $urn2);
/* Build The rest of the required (not used) soap request */
$LogInfo = new SoapVar('', XSD_STRING, null, $urn2, 'LogInfo', $urn2);
$CommonName = $StartDate = new SoapVar($companyName, XSD_STRING, null, $urn2, 'CommonName', $urn2);
$CompanyName = $StartDate = new SoapVar($companyName, XSD_STRING, null, $urn2, 'CompanyName', $urn2);
$AreImplicitMandatesOk = new SoapVar('false', XSD_STRING, null, $urn2, 'AreImplicitMandatesOk', $urn2);
$ParentInfo = new SoapVar('', XSD_STRING, null, $urn2, 'ParentInfo', $urn2);
$UserProperties = new SoapVar('', XSD_STRING, null, $urn2, 'UserProperties', $urn2);
$StartDate = new SoapVar(date('Y-m-d', time()), XSD_STRING, null, $urn2, 'StartDate', $urn2);
$MainPaymentMethod = new SoapVar($mainPaymentMethod, XSD_STRING, null, $urn2, 'MainPaymentMethod', $urn2);
$MainPaymentCondition = new SoapVar($mainPaymentCondition, XSD_STRING, null, $urn2, 'MainPaymentCondition', $urn2);
$ClientType = new SoapVar($clientType, XSD_STRING, null, $urn2, 'ClientType', $urn2);
$MandateInfo = new SoapVar('', XSD_STRING, null, $urn2, 'MandateInfo', $urn2);
$VATInfo = new SoapVar('', XSD_STRING, null, $urn2, 'VATInfo', $urn2);
/* Set the body content */
$Body[] = $LogInfo;
$Body[] = $CommonName;
$Body[] = $CompanyName;
$Body[] = $StartDate;
$Body[] = $MainPaymentMethod;
$Body[] = $MainPaymentCondition;
$Body[] = $ClientType;
$Body[] = $SalesAddress;
$Body[] = $FinancialAddress;
$Body[] = $AreImplicitMandatesOk;
$Body[] = $ParentInfo;
$Body[] = $UserProperties;
$Body[] = $MandateInfo;
$Body[] = $VATInfo;
/* Build entire soap request here */
$data = new SoapVar($Body, SOAP_ENC_OBJECT, null, $urn, 'Client', $urn);
$parameters['Client'] = $data;
这将产生:
<urn:Client> <- Add attribute to this tag
<urn2:LogInfo>
</urn2:LogInfo>
<urn2:CommonName>Some Value</urn2:CommonName>
<urn2:CompanyName>Some Value</urn2:CompanyName>
<urn2:StartDate>2016-01-01</urn2:StartDate>
<urn2:MainPaymentMethod>0001</urn2:MainPaymentMethod>
<urn2:MainPaymentCondition>0003</urn2:MainPaymentCondition>
<urn2:ClientType>XXX</urn2:ClientType>
<urn2:Address>
<urn1:ZipCode>55555</urn1:ZipCode>
<urn1:City>City</urn1:City>
<urn2:GeneralFitness>MAIN</urn2:GeneralFitness>
<urn2:BillingFitness>MAIN</urn2:BillingFitness>
<urn2:Area1>NY</urn2:Area1>
<urn2:CountryCode>US</urn2:CountryCode>
</urn2:Address>
<urn2:AreImplicitMandatesOk>false</urn2:AreImplicitMandatesOk>
<urn2:ParentInfo urn1:dataOmitted="true">
</urn2:ParentInfo>
<urn2:UserProperties urn1:dataOmitted="true">
</urn2:UserProperties>
<urn2:MandateInfo urn1:dataOmitted="true">
</urn2:MandateInfo>
<urn2:VATInfo>
</urn2:VATInfo>
</urn:Client>
但是我需要的是上面所有内容,以及带有所有子元素的Client标记中的属性:
But what I need is all of that above, and an attribute in the Client tag with all of the child elements:
<urn:Client Attr1='XXXX1121111'>
我浏览了所有可以在SO中找到的帖子.我无法为具有子元素的元素生成属性.我尝试使用XSD_ANYXML,并构建了一个视图以插入到SoapVar()中,但是它不起作用,因为我需要命名空间.这很可能是另一个问题的重复,但尚未回答.
I went through all of the posts that I could find in SO. I cannot produce an attribute to element that has child elements. I have tried using XSD_ANYXML, and built a view to insert into a SoapVar(), and it did not work, because I needed the namespaces. This is most likely a repeat of another question, but those have been unanswered.
以下是我去过的一些关于此问题的帖子:
Below are just some of the posts I have been to on this issue:
使用元素创建SOAP请求Zend_Soap_Client和stdObject设置属性
推荐答案
我试图通过SoapVar构建Soap请求.试图将元素嵌套到元素中.我没有这样做,只是创建了一个与需要放入请求的结构相同的关联数组.
I was trying to build the Soap request through SoapVar. Trying to nest elements into elements. Instead of doing that I simply created an associative array in the same structure as the request needed to be in. I.E.
$client->createClient(array('Client' => // Outer most element
// Begin the list of child elements
array('AttributeOfOuterElement' => 'AttrValue',
'ChildElement1' => 'Child1Value' // ..... etc
)
);
哪个是我想要得到的肥皂请求.我删除了所有soapvar元素,只是将数组用作函数中的参数.
Which produced the soap request I was looking to get. I removed all of the soapvar elements, and just used the array as a parameter in the function.
这篇关于PHP soap请求带有元素属性和子元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!