我需要用PHP來構建XML SOAP請求頭,其中輸出看起來是這樣的:格式命名空間SOAP頭使用PHP
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<AuthTokenHeader xmlns="SPP.net/ContractData">
<Token>B1912A8BA7AB6E56D688244D7B</Token>
</AuthTokenHeader>
</soap:Header>
....但我的PHP是不是產生這樣的:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="SPP.net/ContractData">
<SOAP-ENV:Header>
<ns1:AuthTokenHeader>
<Token>373161D1C28</Token>
</ns1:AuthTokenHeader>
</SOAP-ENV:Header>
這是我的PHP代碼:
// define namespace
$NameSpace = 'SPP.net/ContractData';
// build AuthTokenHeader vars
$authTokenVar[] = new SoapVar($TOKEN, XSD_STRING, null, null, 'Token');
// wrap in AuthTokenHeader tags
$header = new SoapVar($authTokenVar, SOAP_ENC_OBJECT, null, null, 'AuthTokenHeader');
// build soap header
$soapHeader = new SoapHeader($NameSpace, 'AuthTokenHeader', $header , false);
// instanciate soap client
$wsdlUrl= "https://gmwstest.sppinc.net/VPP/ContractExchange.asmx?wsdl";
$client = new SoapClient($wsdlUrl,
array(
"trace" => 1,
"exceptions" => 0,
"cache_wsdl" => 0));
// set soap headers
$client->__setSoapHeaders($soapHeader);
這裏是整個XML SOAP請求我需要建立:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<AuthTokenHeader xmlns="SPP.net/ContractData">
<Token>BEB40F7FD43168017ACF3772A91F2B7C2B37A722F6421598D0B61CCD3DBF8928CA18B25970AB6D43FD31A761F15D84A52C9FC315BE9F708F30EE4F08DAB4C74F94894A7D3242102831FB8303684F7FE492A2249CB35FB50030C905DD91F771103C5A1D486CCEA9AAB0D42AC37252B2E350B4E3F24CEE8D0B8CFCE04F1DD7D1B4D7C2A4F1912A8BA7AB6E56D688244D7B</Token> <!--GET TOKEN FROM LOGONRESULT SESSION VARIABLE-->
</AuthTokenHeader>
</soap:Header>
<soap:Body>
<SendContractData xmlns="SPP.net/ContractData">
<contract>
<ContractID>VPP00253221</ContractID> <!--GET ContractID FROM CONTRACT RESPONSE SESSION VARIABLE-->
<AccountNumber/>
<Status>Pending</Status>
<Company>VPP</Company>
<ContractPrefix/>
<DealerCode>10456</DealerCode>
<FirstName>FirstName</FirstName>
<Mi/>
<LastName>Lastname</LastName>
<PhoneNumber>(312)980-6000</PhoneNumber>
<Address1>303 Anytown Lane</Address1>
<Address2>Unit A</Address2>
<City>Yourtown</City>
<StateProvinceAbbr xsi:type="StateEnum">IL</StateProvinceAbbr>
<ZipCode>60601</ZipCode>
<Country>USA</Country>
<OriginatingDepartment>Other</OriginatingDepartment>
<Language>English</Language>
<VIN>1HGCM56705AJMD227</VIN>
<PurchasePrice>2000.00</PurchasePrice>
<SalesTax>0.00</SalesTax>
<DownPayment>200.00</DownPayment>
<AmountFinanced>1800.00</AmountFinanced>
<PolicyType>ServiceContract</PolicyType>
<InServiceDate>2010-03-12T00:00:00</InServiceDate>
<FirstPaymentDate xsi:nil="true"/>
<DealerCost>500</DealerCost>
<ContractHoldersInitialsCoordinates xsi:nil="true"/>
<ContractHoldersInitialsDateCoordinates xsi:nil="true"/>
<ContractHoldersSignatureCoordinates xsi:nil="true"/>
<SignatureDateCoordinates xsi:nil="true"/>
<SellersSignatureCoordinates xsi:nil="true"/>
<PurchaseDate>2014-06-23T14:24:46</PurchaseDate>
<BeginMileage>43650</BeginMileage>
<TermMonths>84</TermMonths>
<TermMileage>100000</TermMileage>
<NumberOfPayments>12</NumberOfPayments>
<CallBackURL>http://NewWarrantyVehicle_Example/Success.php</CallBackURL>
</contract>
</SendContractData>
</soap:Body>
</soap:Envelope>
我的迴應只是回到空白,而如果我在SOAPUI中測試格式正確的XML,我會得到一個有效的響應。我該如何擺脫ns1:標籤? –