sending xml file to web service using sendfile method and php - 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...

Related

Sage Web Services Using PHP SOAP

I am using php SOAP to post lead data to my client's SAGE CRM, the record get created (with crmid returned) but contains empty values. For some unknown reason my xml packet is being ignored.
The SAGE documentation does not give an xml example for adding record (addrecord) to the CRM. Can someone please help?
What is the right xml format for addrecord function?
I know this was a question back in 2013 but better have it answered in case someone else comes looking for a solution.
The following is a sample for the upload of a new opportunity into Sage CRM. I have not seen the xml you are generating but I would start by using add instead of addrecord. I have not used addrecord before so I can't help you understanding this format for uploading data.
Please note the *Specified fields as they are important. Any field to be populated which has a related *Specified field must have it set to true. Otherwise the field might not be populated.
Most of the values on the sample bellow must be replaced by actual values. The SID being the most important one.
You may enter multiple <records> within the <add> tags.
<?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>
<SessionHeader xmlns='http://tempuri.org/type'>
<sessionId>SID</sessionId>
</SessionHeader>
</soap:Header>
<soap:Body>
<add xmlns='http://tempuri.org/type'>
<entityname>opportunity</entityname>
<records xsi:type='opportunity'>
<description>description</description>
<forecast>forecast_value</forecast>
<forecastSpecified>true</forecastSpecified>
<certainty>certainty</certainty>
<certaintySpecified>true</certaintySpecified>
<targetclose>targetclose</targetclose>
<targetcloseSpecified>true</targetcloseSpecified>
<forecast_cid>forecast_cid</forecast_cid>
<forecast_cidSpecified>true</forecast_cidSpecified>
<total_cid>total_cid</total_cid>
<total_cidSpecified>true</total_cidSpecified>
<totalorders_cid>total_orders_cid</totalorders_cid>
<totalorders_cidSpecified>true</totalorders_cidSpecified>
<totalquotes_cid>totalquotes_cid</totalquotes_cid>
<totalquotes_cidSpecified>true</totalquotes_cidSpecified>
<source>source</source>
<type>type</type>
<stage>stage</stage>
<status>status</status>
<assigneduserid>assigneduserid</assigneduserid>
<assigneduseridSpecified>true</assigneduseridSpecified>
<channelid>channelid</channelid>
<channelidSpecified>true</channelidSpecified>
<priority>priority</priority>
<currency>cid</currency>
<currencySpecified>true</currencySpecified>
<primarycompanyid>primarycompanyid</primarycompanyid>
<primarycompanyidSpecified>true</primarycompanyidSpecified>
<primarypersonid>primarypersonid</primarypersonid>
<primarypersonidSpecified>true</primarypersonidSpecified>
</records>
</add>
</soap:Body>
</soap:Envelope>
You can find the web services documentation at https://community.sagecrm.com/user_community/m/cloud_documentation/27076.aspx
Download the wsdl file to get more details about each field and entity available.

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.

SOAP returning invalid XML response

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. :)

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 ...

Set attributes for parameters in SOAP request PHP

I'm trying to use a webservice which only allows SOAP request
as far as I know I must create a request that looks like this
<?xml version="1.0" encoding="utf-8"?>
<SessionCreateRQ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<POS>
<Source PseudoCityCode="SECRET_CODE" />
</POS>
</SessionCreateRQ>
however while adding the parameter to SessionCreateRQ method I don't know how to add the POS parameter called Source and have no clue on how to set the attribute for that parameter
im trying the following in php
$body = array(
'POS' => array('source' => 'PseudoCityCode:SECRET_CODE'));
try
{
$result = $c->SessionCreateRQ($body);
}
but no luck, does anyone has a clue on how should I construct this call properly ?
thanks !
Firstly you need WSDL definition for this service (online or in local file). Any not bad SOAP service provide WSDL to users.
Secondly you need translate WSDL service definition to PHP-code. Try wsdl2php generator. Its generate file with classes, that making calls to web-services.
Your example will be approximately as follows:
require_once 'GeneratedTypes.php';
$client = new SOAPService();
$res = $client->SessionCreateRQ(SECRET_CODE);
p.s. wsdl2php not ideal but it is working :)

Categories