PHP Websample

ArielRauch
Advanced member
Posts: 231
Joined: Thu Aug 07, 2014 10:04 am

PHP Websample

Post by ArielRauch »

Hi,

I am not sure if this is the right place to post this problem - feel free to route me:)



I have installed the web services module and I am trying to get the sample working but I am receiving "connection failed" after entering the credentials. My setup is as follows:



Switch 12 on:

1. Windows 2008R2 Standard

2. HP Server (12 GB RAM)



Web Sample:

1. same server

2. IIS7.5

3. php 5.6

4. Enabled:

a. openssl

b. curl

c. soap

5. phpinfo is working - of course



Switchclient is connecting without problems



Any suggestions how I can debug to understand what is the problem?



Thanks



Ariel
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

PHP Websample

Post by dkelly »

Here's a minimal PHP example I wrote last year.



<?php



error_reporting(E_ALL ^ E_DEPRECATED);



require 'SOAP/Client.php';



$protected_url = "https://localhost:51008";

$my_cert_file = "cacert.pem";



$user = "USERNAME;EN";

$pass = "PASSWORD";



try {

$client = @new SoapClient("butterfly.wsdl",

array( 'local_cert', $my_cert_file,

'trace' => true,

'exceptions' => true,

'login' => $user,

'password' => $pass

));

$client->__setLocation($protected_url);

} catch (Exception $e) {

echo $e->getMessage();

die();

}



$connectReply = $client->CheckConnect();



$credentials = array('login' => $user, 'password' => $pass);

$loginReply = $client->CheckUserNameAndPass($credentials);



$flowsReply = $client->GetFlowList();

#print_r($flowsReply);



foreach ($flowsReply->flowList as $flowId) {

$flowParms = array('flowId' => $flowId);

$flowNameReply = $client->GetFlowName($flowParms);

$flowStateReply = $client->GetFlowState($flowParms);

if ($flowStateReply->FlowState == 3) {

echo $flowId . " " . $flowStateReply->FlowState . " " . $flowNameReply->flowName . "n";



$submitPtsReply = $client->GetSubmitPoints($flowParms);

if (is_array($submitPtsReply->submitPoints)) {

foreach ($submitPtsReply->submitPoints as $submitPtId) {

$submitPtParms = array('flowId' => $flowId, 'submitPointId' => $submitPtId);

$submitPtNameReply = $client->GetSubmitPointName($submitPtParms);

echo " " . $submitPtId . " " . $submitPtNameReply->submitPointData->name . "n";

}

} else {

$submitPtParms = array('flowId' => $flowId, 'submitPointId' => $submitPtsReply->submitPoints);

$submitPtNameReply = $client->GetSubmitPointName($submitPtParms);

print_r($submitPtNameReply);

echo " " . $submitPtsReply->submitPoints . " " . $submitPtNameReply->submitPointData->name . "n";

}

}

}



die();



?>





Dwight Kelly

Advanced Switch concepts with scripting XML, SQL and Javascript seminar @ September 30, 2014 @ Graph Expo & remote classroom
ArielRauch
Advanced member
Posts: 231
Joined: Thu Aug 07, 2014 10:04 am

PHP Websample

Post by ArielRauch »

Hi,

thank you very much for your help!



when running the code I receive an 500 internal error.

I am not a PHP programmer but you require in the code: "SOAP/client.php" which I do not have.



Every advice how to progress would be great.



Ariel
freddyp
Advanced member
Posts: 1023
Joined: Thu Feb 09, 2012 3:53 pm

PHP Websample

Post by freddyp »

Did you put the files of the PHP in the document root folder of the PHP server? You will find the location of that document root folder in the phpinfo. In the settings subfolder of the sample there is a settings.php that also specifies the subfolder (if any) the sample is located in, so you may have to change that.



Freddy
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

PHP Websample

Post by dkelly »

ArielRauch wrote: I am not a PHP programmer


That's going to be a problem. Webservices is a complex topic and can't be solved by cut-n-paste programming. I recommend that you hire an experienced PHP developer.
ArielRauch
Advanced member
Posts: 231
Joined: Thu Aug 07, 2014 10:04 am

PHP Websample

Post by ArielRauch »

dkelly: I am not offended especially not as I know you inspected my LinkedIn profile:)

freddy: Yes, I put it in the root folder and I adjusted the parameters in settings.php



I assume it is an installation/permission issue
User avatar
gabrielp
Advanced member
Posts: 645
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

PHP Websample

Post by gabrielp »

Just curious -- what does the web services module do? I've done a lot with PHP's SoapClient and it's really great. I did some stuff with Switch in Javascript using their Soap class which turned out all right but it would be great if I could roll in my PHP code into Switch somehow.
Free Switch scripts: open-automation @ GitHub
Free Switch apps: open-automation @ Enfocus appstore

Want to hire me? I'm looking for my next gig. Contact me on LinkedIn or via email.
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

PHP Websample

Post by dkelly »

The easiest way to think about Webservices is that you could write your own SwitchClient application using it.



Webservices module enables a developer to connect to a running Switch server, inquire about flows, jobs, etc and submit jobs to submitpoints. Webservices uses an older SOAP protocol. It doesn't support latest SOAP version nor does it support REST.
ArielRauch
Advanced member
Posts: 231
Joined: Thu Aug 07, 2014 10:04 am

PHP Websample

Post by ArielRauch »

Gabriel: The Web services module actually offers the same functionality as the SwitchClient.

It means that you can implement a web application which enables remote users (like your customers) to upload and monitor jobs. It is - if I understand correctly - an open solution to what Connect and Connect all is used today.
ArielRauch
Advanced member
Posts: 231
Joined: Thu Aug 07, 2014 10:04 am

PHP Websample

Post by ArielRauch »

I have made some more research and debugging and got the following error message:

Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in C:inetpubwwwrootincludelibSwitchClientService_v4.0.php:1234 Stack trace: #0 [internal function]: SoapClient->__doRequest(‘__soapCall(‘CheckUserNameAn…’, Array, Array) #2 C:inetpubwwwrootincludelibSwitchClientService_v4.0.php(1281): switchclientService->CheckUserNameAndPass(Object(switchclientCheckUserNameAndPass)) #3 C:inetpubwwwrootincludecheckloginfromswitch.php(33): switchclientService->isAdminCredentials() #4 {main} thrown in C:inetpubwwwrootincludelibSwitchClientService_v4.0.php on line 1234



Any ideas?
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

PHP Websample

Post by dkelly »

Did you change



$protected_url = "https://localhost:51008";



to point to your Server server? Is Switch server running?
ArielRauch
Advanced member
Posts: 231
Joined: Thu Aug 07, 2014 10:04 am

PHP Websample

Post by ArielRauch »

Hi,

in the code you sent me I defined the $protected_url and yrs switch server is running. The switchclient is connecting without any problems.



The code you sent me references SOAP/Client.php which does not reside on my server. It is part of the pear package which is not installed.

In the sample code from enfocus the php file is not referred.

Do I need this package?


dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

PHP Websample

Post by dkelly »

SOAP/Client.php is standard part of PHP distribution. My copy is located in /opt/local/lib/php/SOAP/Client.php
ArielRauch
Advanced member
Posts: 231
Joined: Thu Aug 07, 2014 10:04 am

PHP Websample

Post by ArielRauch »

Unfortunately I am on windows
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

PHP Websample

Post by dkelly »

ArielRauch wrote: Unfortunately I am on windows


Shouldn't matter. What PHP distribution did you install?
Post Reply