PHP Code to generate this - php

I'm trying to get a result from a wsdl file, It however requires authentication and the normal passing of an username and password gives me an error:
Error arguments:
Missing authentication from header
The header should look like the one below;
<wsse:UsernameToken wsu:Id="UsernameToken-3">
<wsse:Username>USERNAME</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PASSWORD</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">jfdkfjdskfjdsklfjsdkf==</wsse:Nonce>
<wsu:Created>TIMESTAMP</wsu:Created>
</wsse:UsernameToken>

Related

Adding SOAP Header to SOAP call in PHP

Using PHP 5.5.9, I'm trying to make a SOAP call and I cannot figure out how to add this header:
<SOAP-ENV:Header>
<wsa:Action>https://websvcs.adtrack.com/SmartLeadImport/Submit_Lead</wsa:Action>
<wsa:MessageID>urn:uuid:GUID</wsa:MessageID>
<wsa:ReplyTo>
<wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>
</wsa:ReplyTo>
<wsa:To>http://stage.adtrack.com/SmartLeadImport/SmartLeadImport.asmx?wsdl</wsa:To>
<wsse:Security SOAP-ENV:mustUnderstand="1">
<wsu:Timestamp wsu:Id="Timestamp-GUID">
<wsu:Created>2017-10-19T14:02:37Z</wsu:Created>
<wsu:Expires>2017-10-19T14:07:37Z</wsu:Expires>
</wsu:Timestamp>
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="SecurityToken-GUID">
<wsse:Username>USERNAME</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">***************</wsse:Password>
<wsse:Nonce>SOMENONSENSE</wsse:Nonce>
<wsu:Created>2017-10-18T14:02:37Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</SOAP-ENV:Header>
What I'm having a real problem with is the nested namespaces. I've tried a couple different approaches.
Adding the XML to a SoapVar, then making that a header, but I can't figure out how to specify namespaces.
Trying to create SoapHeaders, but those came out looking odd, and again, I don't know how to make sure all the namespaces get accounted for.
Any help with this would be amazing. Thanks.

php nusoap server unable to read header security

I'am a newbie to SOAP and I was asked to building a nusoap customized client and server. Actually, I am having a problem reading the following nusoap request header.
<wsa:Action> OTA_HotelRatePlanRQ </wsa:Action>
<wsa:From>
<wsa:Address> urn:connect </wsa:Address>
</wsa:From>
<wsa:To> PartnerURL </wsa:To>
<wsa:ReplyTo>
<wsa:Address> http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous </wsa:Address>
</wsa:ReplyTo>
<wsa:MessageID> 5f2c4c6b-642f-4d07-ad9c-02e5b5cdaa29 </wsa:MessageID>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="SecurityToken-627f1ab1-338a-451f-9829-84f248e57ad8" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username> Username </wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile1.0#PasswordText"> password </wsse:Password>
<wsu:Created> 2014-12-19T16:09:15 </wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
In fact I've had hard time managing to send it from the client side; finally, I was able to send it using serializeEnvelope() and send() nusoap functions. Right now, I can't find a way to read it from the server side. it show the following error message: "Undefined index: wsa". Can any one help me please.
Thank you
In fact I have just found a way to catch the header elements.
here is how:
$request= get_defined_vars();
$request["GLOBALS"]["GLOBALS"]["HTTP_RAW_POST_DATA"] contains all the data received at the server side.

How to send this authentication headers within SOAP requests?

I'm building a PHP application that needs to connect to a webservice which requires a header in every request for authentication. How to send the following along with the requests? Do I need to use SoapHeader along with SoapClient?
<soap:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-
wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="Id-0001334008436683-000000002c4a1908-1"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>[username]</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-
token-profile-1.0#PasswordText">[password]</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
The SOAP envelope has the following structure:
So, you should send a SOAP envelope that has both a Header (like the one you described) and a Body that contains the request itself.
I think you should be using setSoapHeaders on the Client. Refer to the examples in the link.
Hope this helps. Good luck!

SoapClient creating XML

I need to create this xml:
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/04/secext">
<wsse:UsernameToken>
<wsse:Username>user</wsse:Username>
<wsse:Password>password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<vb:getAirportInfo xmlns:vb="http://www.example.com/schema/2005/02/booking.xsd">
<airport>BNE</airport>
<airport>PPP</airport>
<airport>MEL</airport>
</vb:getAirportInfo>
</soapenv:Body>
</soapenv:Envelope>
I am new to using SoapClients and need some help doing this. How would I do it?
To successfuly use SOAP from PHP, you need two things:
The first is SoapClient and/or SoapServer classes bundled with PHP. They work fine, see http://php.net/manual/en/book.soap.php for details.
The second is WsdlDocument library. It generates WSDL description of your services, so other clients can easily use it. See http://code.google.com/p/wsdldocument/
Using SoapClient is very simple, once you initialize it, you will get object on which you can call methods as usual and it will forward these calls to server.
SoapServer is only about creating instance of you service and calling handle method.
None of this includes manual handling of XML you posted. It magically works on it's own (quite literally).
I figured it out. I needed to do two things.
First I needed to create the header section which had the security in it.
$soap_client = new SoapClient("airportinfo.wsdl", array("trace" => 1,"exceptions"=>0));
$header_part = '
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" SOAP-ENV:mustUnderstand="1">
<wsse:UsernameToken>
<wsse:Username>'.$username.'</wsse:Username>
<wsse:Password>'.$password.'</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
';
$soap_var_header = new SoapVar( $header_part, XSD_ANYXML, null, null, null );
$soap_header = new SoapHeader( 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', 'wsse', $soap_var_header, true );
$soap_client->__setSoapHeaders($soap_header);
Second I needed to create an array and pass it to the function that was the WSDL had. I got a list of these by using __getFunctions(). I then used this code to generate the last of the xml
$airports = array("AirportInfoRQ" => array("AirportCode" => "PPP", "AirportCode" => "BNE"));
$responce = $soap_client->AxisTransaction($airports);
This gave me slightly different xml I stated above but it was the correct xml to get the SoapClient working correctly

PHP SOAP generating correct schema

Hi im having some trouble creating a schmea using PHP.
I need to generate something similar to :
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:loc="http://some-url">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://some-url">
<wsse:UsernameToken wsu:Id="UsernameToken-837" xmlns:wsu="http://some-url">
<wsse:Username>account-username</wsse:Username>
<wsse:Password Type="http://some-url">account-password</wsse:Password>
<wsse:Nonce>NuehdiIAyh==</wsse:Nonce>
<wsu:Created>2009-05-07T21:41:49.765Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<loc:getLocation>
<loc:address>some-address</loc:address>
<loc:maximumAge>
<metric>Second</metric>
<units>100</units>
</loc:maximumAge>
<loc:responseTime>
<metric>Second</metric>
<units>100</units>
</loc:responseTime>
<loc:tolerance>LowDelay</loc:tolerance>
</loc:getLocation>
</soapenv:Body>
</soapenv:Envelope>
I've had 0 luck though. I tried some examples using Soapvar,Soapparam, anyone have an idea how I can go by doing this?
NuSOAP is an excellent toolkit for SOAP. It's quite easy to use, and the support is very good.
http://sourceforge.net/project/shownotes.php?release_id=552239
There is an excellent documentation available on how to create SOAP Scheme's.

Categories