php Soap client issue (Security header) - php

Uncaught SoapFault exception: [wsse:InvalidSecurity] Missing wsse:Security header in request
Can someone help me to solve this issue.What this error about??
<?xml version="1.0" encoding="iso-8859-1"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2003/06/secext">
<wsse:UsernameToken wsu:Id="sample"
xmlns:wsu="http://schemas.xmlsoap.org/ws/2003/06/utility">
<wsse:Username>sample</wsse:Username>
<wsse:Password Type="wsse:PasswordText">oracle</wsse:Password>
<wsu:Created>2004-05-19T08:44:51Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
<soap:Body>
<getHello xmlns="http://www.oracle.com"/>
</soap:Body>
</soap:Envelope>
Thanks.

This is common structure with two usertokens, you may need to use one.
<?xml version="1.0" encoding="iso-8859-1"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2003/06/secext">
<wsse:UsernameToken wsu:Id="sample"
xmlns:wsu="http://schemas.xmlsoap.org/ws/2003/06/utility">
<wsse:Username>sample</wsse:Username>
<wsse:Password Type="wsse:PasswordText">oracle</wsse:Password>
<wsu:Created>2004-05-19T08:44:51Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
<wsse:Security soap:actor="oracle"
xmlns:wsse="http://schemas.xmlsoap.org/ws/2003/06/secext">
<wsse:UsernameToken wsu:Id="oracle"
xmlns:wsu="http://schemas.xmlsoap.org/ws/2003/06/utility">
<wsse:Username>oracle</wsse:Username>
<wsse:Password Type="wsse:PasswordText">oracle</wsse:Password>
<wsu:Created>2004-05-19T08:46:04Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
<soap:Body>
<getHello xmlns="http://www.oracle.com"/>
</soap:Body>
</soap:Envelope>
You need to modify your request to this format.

Related

how to connect soap request to php request

below I have attached my soapui request. When I use this PHP code, getting response from the soapui is not working. Please help me find a solution
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Header>
<wsse:Security soap:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-17855236" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>WSBENZTRAVELS</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">p#ss1234</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
<soap:Body xmlns:ns2="http://www.opentravel.org/OTA/2003/05">
<ns2:OTA_AirAvailRQ EchoToken='11868765275150-1300257933' PrimaryLangID='en-us' SequenceNmbr='1' Target='LIVE' TimeStamp='2018-10-08T11:39:35' Version='20061.00'><ns2:POS><ns2:Source TerminalID='Farhath/Farhath'><ns2:RequestorID ID='WSBENZTRAVELS' Type='4' /><ns2:BookingChannel Type='12' /></ns2:Source></ns2:POS><ns2:OriginDestinationInformation><ns2:DepartureDateTime>2018-10-30T00:00:00</ns2:DepartureDateTime><ns2:OriginLocation LocationCode='CMB' /><ns2:DestinationLocation LocationCode='RUH' /></ns2:OriginDestinationInformation><ns2:OriginDestinationInformation><ns2:DepartureDateTime>2018-11-30T00:00:00</ns2:DepartureDateTime><ns2:OriginLocation LocationCode='RUH' /><ns2:DestinationLocation LocationCode='CMB' /></ns2:OriginDestinationInformation><ns2:TravelerInfoSummary><ns2:AirTravelerAvail><ns2:PassengerTypeQuantity Code='ADT' Quantity='1' /></ns2:AirTravelerAvail></ns2:TravelerInfoSummary></ns2:OTA_AirAvailRQ>
</soap:Body>
</soap:Envelope>

Fetching Data Using SOAPUI work but Unable to get data using PHP . Why?

I am Trying to get the same data which I got using SOAPUI in PHP as I can't export in PHP.
See My WSDL file. The function I am calling is AUXTableAdminstration.
If I am fetching the whole table the PHP code works but if I use anything between <web:xDoc> </web:xDoc> then I am having trouble.
Input SOAP Request in SOAPUI
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webcominc.com/">
<soapenv:Header/>
<soapenv:Body>
<web:AUXTableAdministration>
<!--Optional:-->
<web:userName>UserName</web:userName>
<!--Optional:-->
<web:password>Password</web:password>
<!--Optional:-->
<web:action>EXPORTROWS</web:action>
<!--Optional:-->
<web:tableName>ContactData</web:tableName>
<web:xDoc>
<Root>
<Columns>
<Column>ContactInternalId</Column>
<Column>ContactName</Column>
</Columns>
<SearchCriteria>
<Value>12345</Value>
<Value>TestName</Value>
</SearchCriteria >
</Root>
</web:xDoc>
</web:AUXTableAdministration>
</soapenv:Body>
</soapenv:Envelope>
I am searching the row values using the above Request
OUTPUT for SOAPUI
<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:Body>
<AUXTableAdministrationResponse xmlns="http://webcominc.com/">
<AUXTableAdministrationResult>
<Result>
<Status>OK</Status>
<Message>action 'EXPORT' for ContactData succeeded</Message>
<Root>
<Columns>
<Column>CpqTableEntryId</Column>
<Column>ContactInternalId</Column>
<Column>ContactName</Column>
<Column>CustomerInternalId</Column>
<Column>Company</Column>
</Columns>
<Rows>
<Row>
<Value>1234</Value>
<Value>1234</Value>
<Value>Test Value</Value>
<Value>86392</Value>
<Value>Erin Test2</Value>
</Row>
</Rows>
</Root>
</Result>
</AUXTableAdministrationResult>
</AUXTableAdministrationResponse>
</soap:Body>
</soap:Envelope>
PHP file I am using with WSDL:
<?php
header('Content-Type: application/xml; charset=utf-8');
ini_set('soap.wsdl_cache_enable', '0');
$username ="username";
$password = "password";
$action = "EXPORTROWS";
$tablename= "ContactData";
$xml ="<Root><Columns><Column>ContactInternalId</Column><Column>ContactName</Column></Columns><SearchCriteria><Value>86393</Value><Value>Erin Hensz</Value></SearchCriteria></Root>";
$parameters= array('userName' => $username,'password' => $password,'action' => $action,'tableName' => $tablename,xDoc => $xml);
$options = array('soap_version'=>SOAP_1_1,'exceptions'=>true,'trace'=>1,'cache_wsdl'=>WSDL_CACHE_NONE);
$client = new SoapClient('https://sandbox.webcomcpq.com/wsAPI/wssrv.asmx?WSDL' , $options);
$data = $client->AUXTableAdministration($parameters);
echo $result= $client->__getLastResponse();
?>
PHP OUTPUT
<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:Body>
<AUXTableAdministrationResponse xmlns="http://webcominc.com/">
<AUXTableAdministrationResult>
<Result xmlns="http://webcominc.com/">
<Status>NOK</Status>
<Message>EXPORTROWS failed</Message>
<Error>
<ErrorCode>100000</ErrorCode>
<Description>
Object reference not set to an instance of an object.
</Description>
</Error>
</Result>
</AUXTableAdministrationResult>
</AUXTableAdministrationResponse>
</soap:Body>
</soap:Envelope>

How to get the SessionID from soap:header?

I got a soap xml response and I need the SessionID. I tried to use SimpleXml_load_string but got a empty object back. Has anybody any idea how to get the SessionID?
This is the xml response:
<?xml version="1.0" encoding="utf-8"?>
<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>
<Header xmlns="http://www.twinfield.com/">
<SessionID>ca363c52-c12f-4988-b06a-e0c41788e254</SessionID>
</Header>
</soap:Header>
<soap:Body>
<LogonResponse xmlns="http://www.twinfield.com/">
<LogonResult>Ok</LogonResult>
<nextAction>None</nextAction>
<cluster>https://c3.twinfield.com</cluster>
</LogonResponse>
</soap:Body>
</soap:Envelope>
Try using DOM. This is one way:
$s = '<?xml version="1.0" encoding="utf-8"?>
<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>
<Header xmlns="http://www.twinfield.com/">
<SessionID>ca363c52-c12f-4988-b06a-e0c41788e254</SessionID>
</Header>
</soap:Header>
<soap:Body>
<LogonResponse xmlns="http://www.twinfield.com/">
<LogonResult>Ok</LogonResult>
<nextAction>None</nextAction>
<cluster>https://c3.twinfield.com</cluster>
</LogonResponse>
</soap:Body>
</soap:Envelope>';
$doc = new DOMDocument();
$doc->loadXML( $s );
echo $doc->getElementsByTagName('SessionID')->item(0)->nodeValue;
I found some thing useful here.Read this https://groups.google.com/forum/#!topic/soap4r/-5IwhynDoEU:
and
https://scn.sap.com/thread/3543465

send request and get response in php using soap

can some one give me the code for this ... i tried allot using nusoap but steel not getting the result
i gone through many php sites and forums but didnt find the solution . . . .
........................ this is what i want ............................
AvailabilityRequest:
<?xml version="1.0" encoding="utf-8" ?>
<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>
<ns1:clsSecurity soap:mustUnderstand="false" xmlns:ns1="http://tempuri.org/
WsHermes/Service1">
<ns1:WebProviderLoginId>hermestest</ns1:WebProviderLoginId>
<ns1:WebProviderPassword>hermestest </ns1:WebProviderPassword>
<ns1:IsAgent>false</ns1:IsAgent>
</ns1:clsSecurity>
</soap:Header>
<soap:Body>
<AirGetAvailability xmlns="http://tempuri.org/HERMESAPI/AirInventory">
<pobjSecurity>
<WebProviderLoginId>arzoo</WebProviderLoginId>
<WebProviderPassword>arzoo123</WebProviderPassword>
<IsAgent>false</IsAgent>
</pobjSecurity>
<PstrInput><AvailabilityRequest><BookingType>O</BookingType>
<JryDetails><Item><Origin>BLR</Origin><Destination>
BOM</Destination><TravelDate>10/31/2013</TravelDate>
</Item></JryDetails><ClassType>Economy</ClassType>
<AirlineCode>6E,SG,</AirlineCode><AdultCount>1
</AdultCount><ChildCount>0</ChildCount><InfantCount>
0</InfantCount><ResidentofIndia>1</ResidentofIndia>
<DirectAccess>0</DirectAccess><TransFeeFlag>0
</TransF eeFlag></AvailabilityRequest>
</PstrInput>
<PstrFinalOutPut />
<pstrError />
</AirGetAvailability>
</soap:Body>
</soap:Envelope>
........................................................
AvailabilityResponse:
<?xml version="1.0" encoding="utf-8" ?>
<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:Body>
<AirGetAvailabilityResponse xmlns="http://tempuri.org/HERMESAPI/AirInventory">
<AirGetAvailabilityResult xsi:type="xsd:boolean">true</AirGetAvailabilityResult>
<PstrFinalOutPut><?xml version="1.0" encoding="utf-8" standalone="no"?>
<AvailabilityResponse><UserTrackId>RMYOI97999869995927986939247264785431192
</UserTrackId><ResultCode><Status>1</Status></ResultCode><AvailableFlights><O
ngoingFlights><FlightSegments><SegmentDetails><FlightId>11</FlightId><AirlineCod
e>SG</AirlineCode><FlightNumber>344</FlightNumber><AirCraftType>737</AirCraft
Type><Origin>BLR</Origin><Destination>BOM</Destination><DepartureDateTime>
31/10/2013 10:15:00</DepartureDateTime><ArrivalDateTime>31/10/2013 11:55:00
</ArrivalDateTime><Duration>01Hrs 40 Mins</Duration><NumberofStops>0
</NumberofStops><Via /><CurrencyCode>INR</CurrencyCode>
<Currency_Conversion_Rate /><PaxFareDetails><ClassCode>F</ClassCode>
<ClassType>Economy</ClassType><FewSeatIndicator /><Adult>
<BasicAmount>450</BasicAmount><FareBasis />
<FareType>F Refundable</FareType><FuelSurcharge>2150</FuelSurcharge>
<GrossAmount>3214</GrossAmount><Commission /><Value1 /><Value2 />
</Adult></PaxFareDetails></SegmentDetails></FlightSegments></OngoingFlights>
<ReturnFlights /></AvailableFlights></AvailabilityResponse
</PstrFinalOutPut>
<pstrError />
</AirGetAvailabilityResponse>
</soap:Body>
</soap:Envelope>

WSDL Client Problem With PHP

I would like to send the following XML request to a WSDL web service :
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-'.$nonce.'">
<wsse:Username>xxxxx</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">xxxxx</wsse:Password>
</wsse:UsernameToken>
<wsu:Timestamp wsu:Id="Timestamp-'.$nonce.'" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsu:Created>'.$timestamp.'</wsu:Created>
<wsu:Expires>'.$expiration.'</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<prep:requestListeSeancesCtrlAcces>
<codeManifestation>xxxx</codeManifestation>
<!--Optional:-->
<debutIntervalle/>
<!--Optional:-->
<finIntervalle/>
</prep:requestListeSeancesCtrlAcces>
</soapenv:Body>
</soap:Envelope>
How can I do this? I tried PHP soap extension and also NuSOAP with no success :(
Thanks for your help.
Have you tried HttpRequest::send ? E.g. see the example at http://www.php.net/manual/en/function.httprequest-send.php#95734 and fill in your own data:
<?php
//set up variables
$theData = '<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-'.$nonce.'">
<wsse:Username>xxxxx</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">xxxxx</wsse:Password>
</wsse:UsernameToken>
<wsu:Timestamp wsu:Id="Timestamp-'.$nonce.'" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsu:Created>'.$timestamp.'</wsu:Created>
<wsu:Expires>'.$expiration.'</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<prep:requestListeSeancesCtrlAcces>
<codeManifestation>xxxx</codeManifestation>
<!--Optional:-->
<debutIntervalle/>
<!--Optional:-->
<finIntervalle/>
</prep:requestListeSeancesCtrlAcces>
</soapenv:Body>
</soap:Envelope>';
$url = 'http://www.example.com';
$options = array();
//create the httprequest object
$httpRequest_OBJ = new httpRequest($url, HTTP_METH_POST, $options);
//add the content type
$httpRequest_OBJ->setContentType = 'Content-Type: text/xml';
//add the raw post data
$httpRequest_OBJ->setRawPostData ($theData);
//send the http request
$result = $httpRequest_OBJ->send();
//print out the result
echo "<pre>"; print_r($result); echo "</pre>";
?>
when i consume wsdl i use cURL
for modifying headers and Envelopes use this:
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $soapenvelope);

Categories