I want to read the SOAP request which is coming from a .NET WinForms application.
The request is:
<?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>
<HotelPricesRQ xmlns="http://zelsoft.ru/">
<HotelPricesRequest>
<Requestor Login="ZLS" Password="DE52F10D5089096E5D83CA559153D64824AAB0B4" />
<Conditions>
<Condition CityID="0" CountryID="0" HotelID="0" AccommodationID="0" RoomCategoryID="0" RoomTypeID="0">
<Created Begin="2013-10-31T00:00:00" End="2013-10-31T23:59:00+04:00" />
</Condition>
</Conditions>
</HotelPricesRequest>
</HotelPricesRQ>
</soap:Body>
</soap:Envelope>
So how to get the Requestor's Login, Password and the Creattion Begin Date?
I have actually build the response, we've test it and when they send me the request they got the response. I'm just sending the responce without reading the request, but I have to read it and log in diffrent users and send different response. So a real example with the request I've posted above will be much much appreciated.
I don't know why I didn't write the solution I got back then for reading the request,
but here it is, in case someone needs it:
$soap_request = file_get_contents("php://input");
Then I just parse it with the PHP XML Parser Functions like so:
$parser=xml_parser_create();
xml_parse_into_struct($parser,$soap_request,$request_array);
xml_parser_free($parser);
Now you have the data in the $request_array as an array.
You can also use The SimpleXMLElement class to get the data from the request.
Related
I am setting up a soapserver and for some reason when trying to connect file_get_contents('php://input') is empty.
In Fiddler I can see that the clientprogram is actually sending the following:
<?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><AuthenticationHeader xmlns="http://www.cito.nl/DULTService/"><Username>dult</Username><Password>dult</Password><Brincode>99DE00</Brincode></AuthenticationHeader></soap:Header><soap:Body><DULTValidateCredentials xmlns="http://www.cito.nl/DULTService/" /></soap:Body></soap:Envelope>
The soapclient sends two empty calls first, before sending the one above, not sure if that could be related.
Any help is much appreciated!
im trying to build a soap request for the following wsdl method= "GetData"
note that not all the values are required, i've been struggling with this for a week, any help would be very appreciated
Host: xxxxxxxxxxxxxxxx
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "xxxxxxxxxxx"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetData xmlns="xxxxxx">
<key>string</key>
<transferDef>
<Where />
<OrderBy>
<OrderByItems>
<BinaryArithmetic xsi:nil="true" />
<Categorization xsi:nil="true" />
<Function xsi:nil="true" />
<QueryField xsi:nil="true" />
<QueryForm xsi:nil="true" />
</OrderByItems>
</OrderBy>
<ProjectId>string</ProjectId>
<DbType>Production or Test</DbType>
</transferDef>
<token>
<Id>guid</Id>
<LastResponseIdReturned>long</LastResponseIdReturned>
<FirstResponseIdReturned>long</FirstResponseIdReturned>
<NumberOfResponsesReturned>long</NumberOfResponsesReturned>
<DatasetsReturned>long</DatasetsReturned>
<LastDataSet>boolean</LastDataSet>
<ProjectId>string</ProjectId>
<ChangeTrackingVersion>long</ChangeTrackingVersion>
</token>
</GetData>
</soap:Body>
</soap:Envelope>
Nowadays, the best way to consume SOAP WS in PHP is to use a WSDL to PHP such as the PackageGenerator project which will generate the classes to construct the request, then to send the request then to handle the response all that using PHP objects. The generated classes are sufficiently intuitive to construct the request. In addition, it uses composer as the autoloader.
kind of resolved the issue, the problem was with the <token></token> part.
Since it needs a value of type:guid <Id>guid</Id> that as mentioned in the wsdl and xml request, is a dataset created by a .Net library, and it's used to iterate over the samples, it's quite a complicated request, since it needs previous steps to be fulfilled, so i did the request, by omitting the <token> section
If I have a raw XML message that I need to pass in PHP, is there an easy way to pass it?
Something like this:
$xml = '
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Header>
...
</soap:Header>
<soap:Body>
...
<soap:Fault>
...
</soap:Fault>
</soap:Body>
</soap:Envelope>';
$url = 'http://www.myurl.com';
passXmlToSoap($xml,$url);
I am not trying to master using SOAP and I only need to use it to do a very simple thing so I am hoping that I can use raw XML and do it as simply as possible even though that might not be "the right way" to do it.
check this answer:
How to parse SOAP XML?
there should be libraries for parsing XML, but that answer gives you an straightforward way to do it. Good Luck
it works:
$xml = '<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Header>
<Name>Yo</Name>
</soap:Header>
<soap:Body>
<payment>
<uniqueReference>ESDEUR11039872</uniqueReference>
<epacsReference>74348dc0-cbf0-df11-b725-001ec9e61285</epacsReference>
<postingDate>2010-11-15T15:19:45</postingDate>
<bankCurrency>EUR</bankCurrency>
<bankAmount>1.00</bankAmount>
<appliedCurrency>EUR</appliedCurrency>
<appliedAmount>1.00</appliedAmount>
<countryCode>ES</countryCode>
<bankInformation>Sean Wood</bankInformation>
<merchantReference>ESDEUR11039872</merchantReference>
</payment>
</soap:Body>
</soap:Envelope>';
$xml = simplexml_load_string($xml);
print_r( $xml) ;
$xml->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');
foreach ($xml->xpath('//payment') as $item)
{
print_r($item);
}
In any case you should never have to parse XML response nor pass XML request to consume SOAP Web Service.
First if you use the native php SoapClient class you send an object or an array. Then you receive stdClass objects
Second, you should use a WSDL to php generator that generates classes mathing the parameters that has to be sent. It also generated the classes that match the response object. Finally, it generated the classes to send the request. So you can send the request and receive the response very easily without any doubt and without having to deal with XML.
Try PackageGenerator project.
I have an issue with a SOAP request I'm sending to an external ASP Web Service. I have used both SoapUI and PHP's SoapClient class, and both times the same issue occurs - an error that tells me The 'http://www.w3.org/2003/05/soap-envelope:Envelope' element is not declared.
My Request to 'GetStudentEntitlement'
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:adm="http://dest.gov.au/Heims/Admin/" xmlns:heim="http://dest.gov.au/Heims/">
<soap:Header/>
<soap:Body><adm:GetStudentEntitlement>
<heim:entitlementRequest>
<heim:RequestControlTable>
<heim:RequestId>CDD1E704-1298-4D42-AAD9-0031BB90329F</heim:RequestId>
<heim:ClientOrganisationCode>7591</heim:ClientOrganisationCode>
<heim:RequestLocalDateTime>2015-08-10T00:00:00</heim:RequestLocalDateTime>
</heim:RequestControlTable>
<heim:GetEntitlementIn>
<heim:RecordId>CDD1E704-1298-4D42-AAD9-0031BB90329F</heim:RecordId>
<heim:Chessn>1344</heim:Chessn>
<heim:FamilyName>Bassett</heim:FamilyName>
<heim:BirthDate>1988-05-21</heim:BirthDate>
</heim:GetEntitlementIn>
</heim:entitlementRequest>
</adm:GetStudentEntitlement>
</soap:Body>
</soap:Envelope>
The response:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
<soap:Code>
<soap:Value>soap:Sender</soap:Value>
</soap:Code>
<soap:Reason>
<soap:Text xml:lang="en">Heims.WebServices.Extensions.Exceptions.XmlSchemaValidationException: Schema validation errors
at Heims.WebServices.Extensions.SoapFilterExtension.ValidateXmlMessage(SoapMessage message, WebMethodSettings methodSettings) in c:\Userdata\HEIMS.NET\Source\Development\WebService\Heims.WebService.Common\Extensions\SoapFilterExtension.cs:line 408
at Heims.WebServices.Extensions.SoapFilterExtension.ProcessMessageBeforeDeserialise(SoapMessage message) in c:\Userdata\HEIMS.NET\Source\Development\WebService\Heims.WebService.Common\Extensions\SoapFilterExtension.cs:line 200
at Heims.WebServices.Extensions.SoapFilterExtension.ProcessMessage(SoapMessage message) in c:\Userdata\HEIMS.NET\Source\Development\WebService\Heims.WebService.Common\Extensions\SoapFilterExtension.cs:line 173
at System.Web.Services.Protocols.SoapMessage.RunExtensions(SoapExtension[] extensions, Boolean throwOnException)
at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()</soap:Text>
</soap:Reason>
<detail>
<ValidationError>
<RecordId/>
<Element>Envelope</Element>
<Line>1</Line>
<Column>2</Column>
<Description>The 'http://www.w3.org/2003/05/soap-envelope:Envelope' element is not declared.</Description>
</ValidationError>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
I have tried adding and removing the trailing / on the :soap declaration, as well as trying both the 1.1 and 1.2 SOAP versions offered by this web service.
This endpoint request to 'Ping' works correctly:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:adm="http://dest.gov.au/Heims/Admin/">
<soap:Header/>
<soap:Body>
<adm:Ping/>
</soap:Body>
</soap:Envelope>
The result is returned as expected:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<PingResponse xmlns="http://dest.gov.au/Heims/Admin/">
<PingResult>Heims web services pinged. DateTime = 2015-08-10 11:11:00:05</PingResult>
</PingResponse>
</soap:Body>
</soap:Envelope>
So why would the code for one request (the ping) work perfectly, while the other request (GetStudentEntitlement) fails? Both have the soap:Envelope declaration, but the Ping request works fine.
I have also tried using xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" in the soap:Envelope element, but the error remained.
Is it possible that this is a server-side issue from the Web Service itself? Or is something simply going wrong in my code?
Answering my own question.
I contact the Government IT Assistance directly, and had them send me a code example. They were using a highly unusual and modified form of <soap wrapper, forcing me to manually generate the XML using SimpleXMLElement and submit to the Web Service using a wrapped SoapVar with the XSD_ANYXML type.
Did you get any solution to this...
I have encountered same problem today while converting UTL_DBWS utility (oracle plsql) to APEX utilities to make calls to HEIMS web service.
Ping worked but GetStudentEntitlements and AllocateStudentChessn both are failing with same envelop error.
Regards
RC
I am using PHP to connect to a Web Service.
I need to connect to the web service with some login details so I can generate a Ticket to start using the methods available.
Here is some code:
//Connect To WebCrm API
$client = new SoapClient("http://b2b-email.net/apicrm1/webCRMAPI.asmx?wsdl", array('trace' => 1));
//Login
$ticket = $client->Authenticate(array('code' => 'rhgkhgk','user' =>'myusername','password' =>'apass'));
From this in the response soap header a ticket will be generated. This is generated under Ticket Header Then GUID. (See Below)
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<TicketHeader xmlns="http://www.webcrm.com/">
<Guid>TICKET->>>>>>>>e446373e-8fg0-4dfc-b876-41f3bc8990dd</Guid>
</TicketHeader>
</soap:Header>
<soap:Body>
<AuthenticateResponse xmlns="http://www.webcrm.com/">
<AuthenticateResult>
<Message />
<Code>0</Code>
</AuthenticateResult>
</AuthenticateResponse>
</soap:Body>
</soap:Envelope>
I need this ticket ID to perform any other tasks using the web service but how can access it and use it within my code?
I have tried using below:
$response = $client->__getLastResponse();
However this outputs like below:
6d5933d3-46ff-4690-893d-2af04806668c->>>>>>>>0<<<<<ZERO ON THE END
A zero is always on the end when it shouldn't be?
Any help on why this is happening on the best way i can achieve accessing the ticket from Soap Header is greatly appreciated!
As per the manual:
$soapclient->__soapCall("soapmethod", array(parameters), null, $input_headers, &$output_headers);
$output_headers should then contain the headers from the response message.
$client->__getLastResponse() returns the XML of the last response. You are viewing this in your browser, and your browser is trying to interpret this as HTML. Because of this, it will not show any XML tags and only show text. That is why the 0 is displayed. You can view the whole XML in several ways:
View the source of the PHP page
Wrap the echo statement in <xmp></xmp> tags.
Call htmlentities() on the XML before echoing it.