SOAP returning invalid XML response - php

I'm using Zend_Soap_Client object for sending a soap request to another application here is the format of the XML that it's sending to the server:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="urllocation" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:enc="http://www.w3.org/2003/05/soap-encoding"><env:Body><ns1:isAccountActive env:encodingStyle="http://www.w3.org/2003/05/soap-encoding"><param0 xsi:type="xsd:string">thisisatest</param0></ns1:isAccountActive></env:Body></env:Envelope>
I'm using it on the other SOAP servers that I have and seems to work fine but one of the server returned a response "Invalid XML" that is why I'm really wondering why it won't work on that server alone. Any ideas would be greatly appreciated.
Additional Details:
I've tried to commentout the code that calls the method from the Server here is the code:
$client = new Zend_Soap_Client(null,
array(
'uri'=>'http://'.$user->customconfigs['alumniuri'],
'encoding'=>'UTF-8',
'location'=>'http://'.$user->customconfigs['alumnilocation']
)
);
echo "Location: {$user->customconfigs['alumnilocation']} - uri: {$user->customconfigs['alumniuri']}";
$alumniactive = $client->isAccountActive($token);
upon commenting out:
$alumniactive = $client->isAccountActive($token);
the error disappeared.This is the same codes from my other applications and it's working fine from there.

After a long search for the answer to this question I finally found the problem... this code is actually located on a joomla component which I was using the uri same as what I have from the location that would include a character "&" which is illegal on xml standards removing these character from my xml will then cause the SOAP server to accept the request as valid. :)

Related

returning soap xml response for a soap server php

I am trying to create a soap service in php using native php soap server. I have already prepared the wsdl file.
There are basically four methods that can be called with the soap service. The input soap request for one of the request ShowRemittanceDetail is shown below.
<soap-env:body>
<ns1:showremittancedetailrequest>
<username>admin</username>
<password>pass</password>
<refno>USA1956127848</refno>
</ns1:showremittancedetailrequest>
</soap-env:body>
Anyway the soap request does not have a header and I have just shown the body here. I have no problem parsing the soap request. The response should look like this
<?xml version="1.0" encoding="ISO-8859-1"?>
<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:Body>
<ns2:responseType xmlns:ns2="http://tempuri.org/response">
<code>00</code>
<message>Transaction does not exist or is not available</message>
<responseBody>
<responseStr>4</responseStr>
</responseBody>
</ns2:responseType>
</soapenv:Body>
</soapenv:Envelope>
This is a particular response which is generated when the transaction with the reference number is not available in the server.
I have received the soap request and evaluated it. However I have a problem with the return type of the soap response. I cannot generate a valid response. What type of response should a soap server return?
Things I have tried:
I have tried returning an xml string. But the soap client request throws an exception with the following message.
looks like we got no xml document.
I have also tried returing a native php SoapVar() with the same result.
I have tried returning an object response that is specified in the classmap fo the soap server.
e.g. for the example above, I have tried returning a ShowRemittanceDetailResponse object with the same result. (looks like we got no xml document).
I have tried returning a DomDocument Object . The exception thrown in this case is
the encoded object does not have a responseStr property.
I have tried returning an stdClass object with the same fields as the response expects with similar result.
Please help me.
Thanks in advance.
The solution I found was returning a SoapVar object. I didnt have soapui and the client I wrote in php was incorrect. Hence, I had problem verifying the returned xml as the php soap client was throwing an exception. The correct way for me was to return a SoapVar.

Send XML to another server via POST

I'm dealing with an incredibly bad API that requires me to send this XML:
<?xml_version string(335) ""1.0" encoding="utf-16"?>
<GetTicketAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<CompanyName>*name*</CompanyName>
<IntegrationLoginId>*id*</IntegrationLoginId>
<IntegrationPassword>*password*</IntegrationPassword>
<SrServiceRecid>*recordId*</SrServiceRecid>
</GetTicketAction>
via POST (as actionString) to a server that is not under my control. I've tried it with JavaScript (couldn't, cross scripting) and with CURL (got "this needs to be encrypted error"). Encryption is not mentioned anywhere in the docs, which say that it can be done with JS in IE using "full trust."
Content type is application/x-www-form-urlencoded if that helps.
Is there any way to send this with either JS and/or PHP?
After many painful years of this API slowly driving me insane, I discovered that it did NOT want me to send the XML through the standard CURL pattern of
$data = array(
"actionString" => $xml
);
Rather, I was to do:
$data = 'actionString=<?xml_version string(335) ""1.0" encoding="utf-16"?>
<GetTicketAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<CompanyName>*name*</CompanyName>
<IntegrationLoginId>*id*</IntegrationLoginId>
<IntegrationPassword>*password*</IntegrationPassword>
<SrServiceRecid>*recordId*</SrServiceRecid>
</GetTicketAction>'
Future API writers: Let this be a warning. I'm really hoping a crazed psychopath knows where this guy sleeps.

sending xml file to web service using sendfile method and php

I need to send a file to a web service (ebridge) using their SendFile method. This may be too specific to their service for anyone to answer, but I thought I'd give it a try. This is the only documentation I can find regarding the SendFile method:
Purpose
This method is used to submit data for processing by ePortal.
Input parameters
Login (string) The ePortal userID.
Password (string) The ePortal password for that user.
Content (string) This is the document to be uploaded.
Filename (string) This is the name of the file with no path information.
Return Value
SendFileResult (boolean) The boolean return value represents success or failure of the submission of a document.
Here is their sample xml code for posting:
<?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>
<SendFile xmlns="eBridge.WebServices">
<login>mylogin</login>
<password>mypassword</password>
<content>string</content>
<filename>string</filename>
</SendFile>
</soap:Body>
</soap:Envelope>
I am also given a sample of the file (ASN.xml) that I am supposed to send. I've tried putting the xml from this file in between the content tags and just putting "test.xml" in the filename tags. That doesn't work. I know I am making a connection because if I leave it just like it is above I will get a response back, it just returns false since I didn't send anything. Perhaps I am misunderstanding what they want in content and filename? Does anyone have any ideas what I am supposed to do with this?
clarification: What I am wondering is if the xml file goes into 'content' as a string, then what is 'filename' for? Is it actually looking for a file or is this just a name that gets assigned to something later?
Ummm, are you creating a SOAPClient? That xml file is actually the body of a SOAP request and that is encapsulated by the SOAPClient class in PHP.
For the WSDL file: https://www.ebridgeservices.com/ePortalService.asmx?WSDL
Use the SOAPClient Class to build your request to their services. Use $soapReq->SendFile({args and blah here})
and if you don't like the PHP Manual: Here's an example/tutorial.
Their web page has a "live chat". Why don't you ask them?
http://www.ebridgeconnections.com/support/development-kit/API-services.html
But I believe <content> means exactly that: you're supposed to include the entire XML file - as a string - in the SOAP message.
IMHO...

PHP SOAP client send XML

I am trying to create a web service with PHP. The following is my code -
Web Server -
require 'inventory_functions.php';
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$server = new SoapServer("inventory.wsdl");
$server->addFunction("getItemCount");
$server->handle();
Inventory_functions.php -
function getItemCount($upc){
//in reality, this data would be coming from a database
$items = array('12345'=>5,'19283'=>100,'23489'=>'234');
return $items[$upc];
}
My Client Test -
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$client = new SoapClient("http://www.xxx.co.uk/service/inventory.wsdl");
$return = $client->getItemName('12345');
print_r($return);
When I run this everythign is OK. the number "5" will output in my browser. WhatI really need is some help in how to go about sending data via XML to the SOAP server, from their I will add this data to MySQL.
How would I send the XML vie the client test?
Thanks
I'm not sure I understand your question. You want to know what XML input you should give your web-service in order to send for instance the value "5"?
In order to do that you should first analyse the wsdl file that is generated, then, depending on your programming language of choice for the client, you may generate a client Stub to interact with the Web-Service itself.
Alternatively, you may issue an HTTP POST with the XML directly to the web-service (should look something like this):
POST /service/mywebservice.php HTTP/1.1
Host: www.xxx.co.uk
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "<your.webservice.namespace>/getItemCount"
<?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>
<getItemCount xmlns="<your.webservice.namespace>">
<value>5</value>
</getItemCount>
</soap:Body>
</soap:Envelope>

how to return custom types with php soap server?

I'm in with PHP SoapServer working in non-wsdl mode. I have the server set up to handle the data and return a response using setClass(). I tried returning an associative array, but that translates into SOAP maps with items, keys and values. I'd like to respond with the following:
<soap:Body>
<AsyncResponseOperationResponse xmlns="http://www.sample.com/">
<AsyncResponseOperationResult>
<Succeeded>true</Succeeded>
<Comments>
The operation was a success
</Comments>
</AsyncResponseOperationResult>
</AsyncResponseOperationResponse>
</soap:Body>
The variables would be whether success is true or false, and the comments.
I've been trying to read about the 'typemap' option, but it is not very well documented, and what I've found so far has only confused me further. The resources I've found so far are the php unit tests, like this one and this one, as well as this stackoverflow question
Can anyone provide me an example that does what I'm trying to do? I think I would be alright switching to wsdl mode with autodiscover (using Zend's Soap Server), if that comes up as a solution.
Edit:Until I figure out how to do it the right way, I'm just writing out all the XML manually.
header("Content-type: text/xml");
echo "<?xml version="1.0" encoding="utf-8"?><soap:Envelope ...

Categories