PHP - Simple Soap Call To .net Service
Hi all,
I'm a newbie in PHP trying to move away from the .net platform. I seem to have run into my first challenge passing a complex type back to my web service. The web service is a live test site to test against. I've tested the service on .net and it works fine...but I think I'm missing something as I try porting over to PHP? I've written some short code to keep it simple: <?php $SearchCriteria = array("ObjectType"=>1); $parameters['user'] = "johndoe1"; $parameters['password'] = "snowball"; $parameters['SearchCriteria'] = $SearchCriteria ; $client = new SoapClient("https://servicestest.mcquaig.com/mws.asmx?WSDL"); $result = $client->__soapCall('Find', $parameters); ?> ....against this portion of XML: <s:element name="Find"> <s:complexType> <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="user" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="password" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="criteria" type="tns:SearchCriteria"/> </s:sequence> </s:complexType> </s:element> <s:complexType name="SearchCriteria"> <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="AccountName" type="s:string"/> <s:element minOccurs="1" maxOccurs="1" name="ApplySharing" type="s:boolean"/> <s:element minOccurs="1" maxOccurs="1" name="CGType" type="s:int"/> <s:element minOccurs="0" maxOccurs="1" name="ClientRefID" type="s:string"/> <s:element minOccurs="1" maxOccurs="1" name="Composites" type="s:int"/> <s:element minOccurs="0" maxOccurs="1" name="ConfNo" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="Email" type="s:string"/> <s:element minOccurs="1" maxOccurs="1" name="Expired" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="ExpiryTSA" type="s:dateTime"/> <s:element minOccurs="1" maxOccurs="1" name="ExpiryTSZ" type="s:dateTime"/> <s:element minOccurs="0" maxOccurs="1" name="FirstName" type="s:string"/> <s:element minOccurs="1" maxOccurs="1" name="FormLangID" type="s:unsignedLong"/> <s:element minOccurs="1" maxOccurs="1" name="FunctionalArea" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="Gender" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="Industry" type="s:int"/> <s:element minOccurs="0" maxOccurs="1" name="JobTitle" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="LastName" type="s:string"/> <s:element minOccurs="1" maxOccurs="1" name="LastUsedTSA" type="s:dateTime"/> <s:element minOccurs="1" maxOccurs="1" name="LastUsedTSZ" type="s:dateTime"/> <s:element minOccurs="1" maxOccurs="1" name="NoRelated" type="s:boolean"/> <s:element minOccurs="1" maxOccurs="1" name="ObjectType" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="OrgID" type="s:unsignedLong"/> <s:element minOccurs="1" maxOccurs="1" name="Position" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="ProfileType" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="Recursive" type="s:boolean"/> <s:element minOccurs="1" maxOccurs="1" name="Status" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="Type" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="UnitsRemain" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="UnitsRemainGT" type="s:boolean"/> </s:sequence> </s:complexType> Nothing I seem to do works. I end up with the same error: Uncaught SoapFault exception: [soap:Server] Server was unable to process request. ---> Value does not fall within the expected range. Using NuSoap as: <?php require_once('lib/nusoap.php'); $SearchCriteria = array("ObjectType"=>1); $wsdlURL = "https://servicestest.mcquaig.com/mws.asmx?WSDL"; $soap = new nusoap_client($wsdlURL); $parameters['user'] = "johndoe1"; $parameters['password'] = "snowball"; $parameters['criteria'] = $SearchCriteria ; $result = $soap->call("Find", $parameters); if($error = $soap->getError()){ die($error);} ?> I get this error: soap:Client: Server did not recognize the value of HTTP Header SOAPAction: . I'm stumped and sure it's something small, but I just don't see what I'm missing?? Any suggestions are greatly appreciated!! Gary Similar TutorialsOkay, On my original problem, I have been able to authenticate with the web service login service, and extract a cookie as follows from the web-service: $s_Cookie = $agLoginService->agGetCookie(); $s_Cookie = AGSESSION=oxhbjcKtPw5sOymAD8m8KcKR6JL4i+TIE5mZxwOrXLwCRr8iTOvPxA==; Now, I create data access soapclient: $agDataService = new SoapClient($s_DataURL, $a_SoapOptions); //yes I know I should build my own class wrapper around soapClient, but I am trying to make sure I know what to build before I do next in the process I need to set the cookie for the data access service. I tried using: <b>$agDataService->__setCookie('cookie', $s_Cookie);</b> but I don't think it's right because when I call any of the service's functions, I get no data back. This is what their engineer had to say ( he is no help in php at all) This is a question referring the http headers. He needs to set the cookies as given in the examples on the wiki page. The cookie is specified in a response http header as: Set-Cookie. So the http headers he got back are correct. The cookie he has to set is AGSESSION=oxhbjcKtPw5sOymAD8m8KcKR6JL4i+TIE5mZxwOrXLwCRr8iTOvPxA==; There should be an api for setting the cookie if not there is one for setting the http header. Set the http header name for the request (cookie - notice that is different than what you get back from an http response - read the rfc spec for http for all of the details) then set the value. The semi colon at the end is the delimiter for http headers (in the rfc). That is all he needs to do if he gets back some login error that means the cookies did not get set correctly. Any ideas or help will be great. Thank you. Hi! I need to retrieve data from a WCF Web Service and don't seem to be connecting when the "new SoapClient" is called. I am using php version 5.2. The service requires 2 Parmameters, an account ID and a comma separated email list. Can someone please tell me what I am doing wrong? Thanks! Code: [Select] <?php header('Content-Type: text/xml'); $client = new SoapClient('http://www.zbestlistings.com/WCF/Primedia.svc?wsdl'); $response = $client->GetPropertyXML(array( "AccountID" => "12807175152", "eMailList" => "Sheryl@Rentingslc.com, Tenants@Rpmwestvalley.com, Tom@Rpmsouthernutah.com" )); echo $response; ?> Curious how to set a returned value from a web service to a php variable? Code: [Select] $tid= $_POST['tid']; $client = new SoapClient("http://www.sitename.com/WebSvc.asmx?WSDL"); $result = $client->getName(array('tid'=>$tid)); echo json_encode($result); Returns this: Code: [Select] {"getNameResult":{"count":1,"results":{"TaggedText":{"tid":"001","text":"John Smith"}}}} How do I set a php variable $RetName to equal John Smith? I tried Code: [Select] $RetName = $text; But that didn't work. Any help is apprecaited. Thanks, sanchez OVERVIEW: The code is about making call to the escreen web service using SOAP and Curl with client authentication required. Currently I am not getting any result only HTTP 403 and 500 errors. The call requires client authenticate cert to be on the callng site. CODE: $content = "<TicketRequest> <Version>1.0</Version> <Mode>Test</Mode> <CommitAction></CommitAction> <PartnerInfo> <UserName>xxxxxxxxxx</UserName> <Password>xxxxxxxxxxx</Password> </ PartnerInfo> <RequestorOrderID></RequestorOrderID> <CustomerIdentification> <IPAddress></IPAddress> <ClientAccount>xxxxxxxxxx</ClientAccount> <ClientSubAccount>xxxxxxxxxx</ClientSubAccount> <InternalAccount></InternalAccount> <ElectronicClientID></ElectronicClientID> </CustomerIdentification> <TicketAction> <Type></Type> <Params> <Param> <ID>4646</ID> <Value></Value> </Param> </Params> </TicketAction> </TicketRequest>"; $wsdl = "https://services.escreen.com/SingleSignOnStage/SingleSignOn.asmx"; $headers = array( "Content-type: text/xml;charset=\"utf-8\"", "Accept: text/xml", "Cache-Control: no-cache", "Pragma: no-cache", // "SOAPAction: \"\"", "Content-length: ".strlen($content), ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $wsdl); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_VERBOSE, '1'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $content); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, '1'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, '1'); //curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml")); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); //curl_setopt($ch, CURLOPT_HTTPHEADER, array('SOAPAction: ""')); curl_setopt($ch, CURLOPT_CAPATH, '/home/pps/'); curl_setopt($ch, CURLOPT_CAINFO, '/home/pps/authority.pem'); curl_setopt($ch, CURLOPT_SSLCERT, 'PROTPLUSSOL_SSO.pem'); curl_setopt($ch, CURLOPT_SSLCERTPASSWD, 'xxxxxxxxxxxx'); $output = curl_exec($ch); // Check if any error occured if(curl_errno($ch)) { echo 'Error no : '.curl_errno($ch).' Curl error: ' . curl_error($ch); } print_r($output); QUESTIONS: 1. I need to call the RequestTicket method and pass the XML string to it. I don't know how to do it here(pass the method name to call). 2. For client authentication they gave us three certs, one root cert, one intermediate cert and a client authentication cert PROTPLUSSOL_SSOpem(it was a .pfx file). Since we are on linux we converted them to pem . In curl calls I could not find way to how to include both the root cert and the intermediate cert ,so I combined them by making a new pem file and copying the intermediate cert and them the root cert and naming it authority.pem . I am not sure whether it works or not and would like your opinion. 3. For the current code Iam getting the error Error no : 77 Curl error: error setting certificate verify locations: CAfile: /home/pps/authority.pem CApath: /home/pps/ If I disable the curl error message,I am getting blank page with page title 403 - Forbidden. Access is denied. If I comment out the CURLOPT_CAPATH and CURLOPT_CAINFO lines it gives http 500 error page with the message as content and the following at the top. > HTTP/1.1 500 Internal Server Error. Cache-Control: private Content-Type: text/html Server: Microsoft-IIS/7.5 X-AspNet-Version: 1.1.4322 X-Powered-By: ASP.NET Date: Thu, 02 Sep 2010 14:46:38 GMT Content-Length: 1208 If I comment out as above and also CURLOPT_SSLCERT and CURLOPT_SSLCERTPASSWD it gives 403 error with the message as content. So I would request you to help me out by pointing out whats wrong with the current code. Thank you. HI, I need to know how to get the response objects from a webserve call. I call the following webservice: $params = array('mobiUser'=>"WJBASSON",'mobiPass'=>"83dop"); $soap = new SoapClient('http://172.18.22.182/csp/ampath/ReportGeneration.Mobi.Services.cls?WSDL'); $result = $soap->login($params); When I do var_dump($result) I receive the following: stdClass Object ( [loginResult] => stdClass Object ( [MobiRegUserID] => 34 [MobiRegUserName] => WJBasson ) ) I need to know how can I get the values of objects MobiRegUserID and MobiRegUserName ?? This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=353390.0 I'm trying to use a simple wsdl file and make a soap call but for the life of me I can't get it to work. Here's the wsdl file: <?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions targetNamespace="urn:gnHPD_Staging_Table_Submit_Generic" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:s="urn:gnHPD_Staging_Table_Submit_Generic" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <wsdl:types> <xsd:schema elementFormDefault="qualified" targetNamespace="urn:gnHPD_Staging_Table_Submit_Generic"> <xsd:element name="Submit" type="s:InputMapping"/> <xsd:complexType name="InputMapping"> <xsd:sequence> <xsd:element name="Assigned_To_Group" type="xsd:string"/> <xsd:element name="AutoPush" type="s:AutoPushType"/> <xsd:element name="Case_Type" type="s:Case_TypeType"/> <xsd:element name="Category" type="xsd:string"/> <xsd:element name="Description" type="xsd:string"/> <xsd:element name="Details" type="xsd:string"/> <xsd:element name="Entry_Number" type="xsd:string"/> <xsd:element name="Integration_Application" type="xsd:string"/> <xsd:element name="Item" type="xsd:string"/> <xsd:element name="Priority" type="s:PriorityType"/> <xsd:element name="Source" type="s:SourceType"/> <xsd:element name="Submitter_UNIX" type="xsd:string"/> <xsd:element name="Summary" type="xsd:string"/> <xsd:element name="Type" type="xsd:string"/> </xsd:sequence> </xsd:complexType> <xsd:simpleType name="AutoPushType"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="Auto Push"/> </xsd:restriction> </xsd:simpleType> <xsd:simpleType name="Case_TypeType"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="Incident"/> <xsd:enumeration value="Question"/> <xsd:enumeration value="Request"/> <xsd:enumeration value="Problem"/> </xsd:restriction> </xsd:simpleType> <xsd:simpleType name="PriorityType"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="4"/> <xsd:enumeration value="3"/> <xsd:enumeration value="2"/> <xsd:enumeration value="1"/> </xsd:restriction> </xsd:simpleType> <xsd:simpleType name="SourceType"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="Phone"/> <xsd:enumeration value="Requester"/> <xsd:enumeration value="Email"/> <xsd:enumeration value="Web"/> <xsd:enumeration value="NMP"/> </xsd:restriction> </xsd:simpleType> <xsd:element name="SubmitResponse" type="s:OutputMapping"/> <xsd:complexType name="OutputMapping"> <xsd:sequence> <xsd:element name="StagingTable_ID" type="xsd:string"/> <xsd:element name="HelpDesk_ID" type="xsd:string"/> </xsd:sequence> </xsd:complexType> <xsd:element name="AuthenticationInfo" type="s:AuthenticationInfo"/> <xsd:complexType name="AuthenticationInfo"> <xsd:sequence> <xsd:element name="userName" type="xsd:string"/> <xsd:element name="password" type="xsd:string"/> <xsd:element minOccurs="0" name="authentication" type="xsd:string"/> <xsd:element minOccurs="0" name="locale" type="xsd:string"/> <xsd:element minOccurs="0" name="timeZone" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:schema> </wsdl:types> <wsdl:message name="SubmitSoapOut"> <wsdl:part element="s:SubmitResponse" name="parameters"/> </wsdl:message> <wsdl:message name="SubmitSoapIn"> <wsdl:part element="s:Submit" name="parameters"/> </wsdl:message> <wsdl:message name="ARAuthenticate"> <wsdl:part element="s:AuthenticationInfo" name="parameters"/> </wsdl:message> <wsdl:portType name="gnHPD_Staging_Table_Submit_GenericPortType"> <wsdl:operation name="Submit"> <wsdl:input message="s:SubmitSoapIn"/> <wsdl:output message="s:SubmitSoapOut"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="gnHPD_Staging_Table_Submit_GenericSoapBinding" type="s:gnHPD_Staging_Table_Submit_GenericPortType"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="Submit"> <soap:operation soapAction="urn:gnHPD_Staging_Table_Submit_Generic/Submit" style="document"/> <wsdl:input> <soap:header message="s:ARAuthenticate" part="parameters" use="literal"></soap:header> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="gnHPD_Staging_Table_Submit_GenericService"> <wsdl:documentation>Generic Submit for HD</wsdl:documentation> <wsdl:port binding="s:gnHPD_Staging_Table_Submit_GenericSoapBinding" name="gnHPD_Staging_Table_Submit_GenericSoap"> <soap:address location="http://gremedydev:9090/midtier/services/ARService?server=gremedydev&webService=gnHPD_Staging_Table_Submit_Generic"/> </wsdl:port> </wsdl:service> </wsdl:definitions> Here's my php code: $params = array( "Submitter_UNIX"=>'myunix', "Source"=>'Web', "Summary"=>'Test1', "Description"=>'Test1', "Category"=>'test services', "Type"=>'test solutions', "Item"=>'Problem', "Assigned_To_Group"=>'test solutions', "Case_Type"=>'Problem', "Priority"=>'4', "AutoPush" => 'Auto Push', "Details"=>'Test Details', "Entry_Number"=>'', "Integration_Application"=>'MyMobile' ); $client = new SoapClient('http://gremedydev:9090/midtier/WSDL/gremedydev/gnHPD_Staging_Table_Submit_Generic',array('trace' => 1 )); $result = $client->Submit($params); I get this reply Code: [Select] Fatal error: Uncaught SoapFault exception: [ns1:Server.userException] MessageType: 2 MessageNum: 149 MessageText: A user name must be supplied in the control record AppendedText: in D:\Inetpub\wwwroot\myMobile\test\testwsdl2.php:29 Stack trace: #0 [internal function]: SoapClient->__call('Submit', Array) #1 D:\Inetpub\wwwroot\myMobile\test\testwsdl2.php(29): SoapClient->Submit(Array) #2 {main} thrown in D:\Inetpub\wwwroot\myMobile\test\testwsdl2.php on line 29 The only thing I can think of missing here is headers but I have no idea how to configure that. Any insight is greately appreciated! This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=319682.0 I can call the following function successfully as a single php program // Acknowledge and clear the orders function ack($client, $merchant, $id) { $docs = array('string' => $id); $params = array('merchant' => $merchant, 'documentIdentifierArray' => $docs); $result = $client->call('postDocumentDownloadAck', $params); return $result; } with $result = ack($t, $merchant,'2779540483'); successful output [documentDownloadAckProcessingStatus] => _SUCCESSFUL_ [documentID] => 2779540483 I'm trying to figure out how to call this function as an object from another program. Trying the following gives error ***Call to a member function call() on a non-object*** function postDocumentDownloadAck($t, $merchant, $id) { $this->error = null; $docs = array('string' => $this->id); $params = array('merchant' => $this->merchant, 'documentIdentifierArray' => $docs); ** I've tried the following which does nothing $result = $this->soap->call('postDocumentDownloadAck', $params); ** I've tried the following - which gives error "Call to a member function call() on a non-object" $result = $this->t->soap->call('postDocumentDownloadAck', $params); if($this->soap->fault) { $this->error = $result; return false; } return $result; } *** calling program snippet for above function $merchant= array( "merchant"=> $merchantid, "merchantName" => $merchantname, "email"=> $login, "password"=> $password); $t = new AmazonMerchantAPI($merchantid, $merchantname, $login, $password); $documentlist= $t->GetAllPendingDocumentInfo('_GET_ORDERS_DATA_'); $docid = $documentlist['MerchantDocumentInfo'][$i]['documentID']; $docs = array('string' => $docid); $ackorders = $t->postDocumentDownloadAck($t, $merchant,$docs); Any ideas of what I'm doing wrong are greatly appreciated. I'm getting the following result from a web service call. I'd like to pass it to another page, possibly using sessions, and then access specific values on that page, such as FirstName.
stdClass Object ( [GetProspectAsJSONResult] => [ { "ProspectId": xxxxxx, "Keycode": "Test", "FirstName": "Test", "LastName": "Test", "Company": "Test","Email": null } ] )
I'm not sure what the best way to do this is.
Thanks!
Hi Guys/Gals, I am new to PHP and when I say new, I mean I know a variable is $variable name... that is about it. I am a .Net developer, always was, now I have to learn some php. I have a .Net payment gateway service that I would like to reference from a php site. I was hoping anyone could point me in the right direction on how to go about adding a .Net Service and pointing to it in PHP. Please note this is a WPF service, thus it is a .svc page not a .asmx and it is hosted and running on iis on a server. Please some guidance? Any help would be appreciated. Hi, guys. I just developed and published first version of 12framework for iOS which can call also PHP web services.
It is web service client which generates dynamic forms from web service results, and enables insert, update and delete of records. You can simply change result field type to text, memo, date, bool.
I also made some simple PHP web service to test functionallity of application, so I will really appreciate your feedback. iOS is locked platform, so 12framework provides possibility, to make some useful data forms that works as native application. Link: https://itunes.apple...88083?ls=1&mt=8
Hello
I am looking for a way to log all incoming requests to a nusoap web service to a file.. any suggestions?
Thanks
I have service /usr/lib/systemd/system/socketserver.service defined as follows: [Unit] Description=Socket Server After=syslog.target [Service] ExecStart=/usr/bin/php /var/www/socket/server.php Restart=on-abort Restart=on-failure RestartSec=10s [Install] WantedBy=multi-user.target When hitting the following lines: $cmd="tshark -f 'port 1337' -i eno16780032 -a duration:4 -w /var/www/socket/tmp/test.pcap"; $status = exec($cmd, $output); syslog(LOG_INFO, 'results: '.json_encode($output).' status: '.($status?'success':'false')); I get the following: Jun 04 18:58:56 tapmeister.com php[43111]: Running as user "root" and group "root". This could be dangerous. Jun 04 18:58:56 tapmeister.com php[43111]: Capturing on 'eno16780032' Jun 04 18:58:56 tapmeister.com kernel: device eno16780032 entered promiscuous mode Jun 04 18:59:00 tapmeister.com kernel: device eno16780032 left promiscuous mode Jun 04 18:59:00 tapmeister.com php[43111]: 0 packets captured Jun 04 18:59:00 tapmeister.com Server[43111]: results: [] status: false Sure enough, exec('whoami') confirms I am running as root. Probably shouldn't be. How would you recommend configuring? PS. the three lines shown regarding tshark are executed via an asynchronous request and are not in the main loop. Hi, I'm new to PHP and wondered if anyone could help... I am consuming an asmx webservice using PHP code. (Later to make a widget for wordpress). I can receive all the data, but it is in one very big xml file. I want to be able to convert this data, so I can make it more readable. Could really do with help as I don't have a clue how to convert it. ANy ideas? Hi everyone. I am looking at creating my application's back end with PHP, which returns all data with Jason or simplexml. I have tried Slim once, but think there should be something easier to use. Can anyone give me suggestions on what I can use which is easy to catch on, and maybe an example? Appreciate it. Kind regards Hello, I use loads of different servers at work and they all run seperate services that I need to keep my stuff running. I want to build a simple webpage that will poll the services and display the current state by colour. EG have table that lists the services in green and have them turn red if the service stops unexpectedly. I can build the tables and stuff, I just don't know how to retrieve the state of a service. I've been messing about with some ideas but nothing is working. eg lets say I have two servers each with one service: service one | IP Address of server | RUNNING service two | IP Address of server | STOPPED Has anyone got any ideas? Thanks!! I am trying to create a web service using restful service tonic frame work to pull data from my website www.serviidb.com and I can print_r the output to firefox poster. I am using SQL queries to pull the data form a mysql database. I would like to be able to select the query for the data I want at the beginning of the code and select the output format at the end. I am looking at having sections of the code to get "plugins", "video", "audio", and "user". I am thinking about use select case to determine the mysql query to run. I have programming exp in VB, basic and fortran. Here is the URL I am using for the get command. Code: [Select] http://serviidb.com/api/plugins here is the code I am using right now. Code: [Select] <?php class TaskDataManager { public static function get($taskId, $input){ echo $taskid . "\n"; //Connect To Database $hostname='hostname'; $username='username'; $password='password'; $dbname='dbname'; mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.'); mysql_select_db($dbname); //echo 'taskid: ' . $taskId . "\n"; if($taskId=="plugins"){ //echo $input . "\n"; $plgnsql='SELECT taxonomy_term_data.name, field_revision_field_revision.field_revision_value as version, file_managed.uri as URL' . ' FROM taxonomy_term_data ' . ' left join field_data_field_plugins on taxonomy_term_data.tid = field_data_field_plugins.field_plugins_tid ' . ' left join field_revision_field_revision on field_revision_field_revision.revision_id = field_data_field_plugins.revision_id ' . ' left join file_usage on field_data_field_plugins.entity_id = file_usage.id' . ' left join file_managed on file_usage.fid = file_managed.fid' . ' WHERE (field_data_field_plugins.bundle ="plugin")' . ' '; //$format='json' $result = mysql_query($plgnsql); //$mark =jsob_encode("plugins"); $plugins = array(); //echo $result . "\n"; //$response->addHeader('Content-type', 'application/json'); while($response = mysql_fetch_array($result, MYSQL_ASSOC)){ $response[URL] = substr_replace($response[URL],'http://serviidb.com/sites/default/files/',0,9); $reponse = json_encode($response); print_r ($reponse) . "\n"; } //print_r ($response) . "\n"; return true; } if($taskId=="video"){ echo $input . "\n"; //echo "started feed code" . "\n"; return true; } } } ?> Here is the output I am getting. I am trying to figure out how to get the json output to look like the second code below. Code: [Select] {"name":"Blip TV","version":"0","URL":"http:\/\/serviidb.com\/sites\/default\/files\/createplugin\/BlipTVUrlExtractor.groovy"}{"name":"CBS","version":"0","URL":"http:\/\/serviidb.com\/sites\/default\/files\/createplugin\/CBS.groovy"}{"name":"iPlayer (UK)","version":"1","URL":"http:\/\/serviidb.com\/sites\/default\/files\/createplugin\/IPlayer.groovy"}{"name":"4oD (UK)","version":"1","URL":"http:\/\/serviidb.com\/sites\/default\/files\/createplugin\/Channel4od.groovy"}{"name":"YouTube","version":"1","URL":"http:\/\/serviidb.com\/sites\/default\/files\/createplugin\/youtube.groovy"}{"name":"LiveFeeds","version":"3","URL":"http:\/\/serviidb.com\/sites\/default\/files\/createplugin\/livefeeds.groovy"}{"name":"GameSpot","version":"1","URL":"http:\/\/serviidb.com\/sites\/default\/files\/createplugin\/gamespot.groovy"} Want. Code: [Select] {"plugins":[{"name":"Blip TV", "version":0, "url":"http:\\serviidb.com/sites/default/files/Create Plugin/BlipTVUrlExtractor.groovy"},{"name":"CBS", ....}]} I am also trying to figure out how to get the output in the xml format also. Thanks is advance for the help. I'm able to consume a local WSDL into PHP, and pass/return basic data successfully, but when I attempt to pass in objects that correspond to a complextype in the WSDL, I get the following error: SoapFault exception: [soapenv:Server] javax.xml.ws.WebServiceException: com.ibm.websphere.sca.ServiceRuntimeException: An error occurred while parsing native data: The error message is: java.lang.IllegalArgumentException: Mismatched parameter count: expecting 1 items, but got more.. Caused By: java.lang.IllegalArgumentException: Mismatched parameter count: expecting 1 items, but got more.: caused by: An error occurred while parsing native data: The error message is: java.lang.IllegalArgumentException: Mismatched parameter count: expecting 1 items, but got more.. Caused By: java.lang.IllegalArgumentException: Mismatched parameter count: expecting 1 items, but got more. in C:\wamp\www\SugarCE\testSOAPShawn.php:65 Stack trace: #0 [internal function]: SoapClient->__call('establishIdenti...', Array) #1 C:\wamp\www\SugarCE\testSOAPShawn.php(65): SoapClient->establishIdentity(Object(stdClass), Object(stdClass)) #2 {main} Here is the snippets from the WSDL: Code: [Select] <xsd:element name="establishIdentity"> − <xsd:complexType> − <xsd:sequence> − <xsd:element name="processId" nillable="true" type="xsd:string"> − <xsd:annotation> − <xsd:documentation> Identifies a specific instance of the dialogue process. Returned from the start() operation. </xsd:documentation> </xsd:annotation> </xsd:element> − <xsd:element name="identityAttributes" nillable="true" type="bons1:IdentityAttributes"> − <xsd:annotation> − <xsd:documentation> Key identifying attributes of a program participant. </xsd:documentation> </xsd:annotation> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> Here is my code with comments where the error occurs: <?php set_time_limit(0); require_once('nusoap.php'); $client = new SoapClient('C:\wsdl\BenefitDeterminationProcess_BenefitDialogueServiceSOAP.wsdl', array('trace' => 1)); $start = $client->__soapCall('start', array(new SoapParam((string)'GenesisID', 'prefix')), array('soapaction' => 'C:\wsdl\BenefitDeterminationProcess_BenefitDialogueServiceSOAP\start')); $processID = $start; $exchange = $client->__soapCall('exchangeOptions', array(new SoapParam($processID, 'processId')), array('soapaction' => 'C:\wsdl\BenefitDeterminationProcess_BenefitDialogueServiceSOAP\exchangeOptions')); $identityAttributes = new StdClass(); $identityAttributes->IdentityAttributes = new StdClass(); $identityAttributes->IdentityAttributes->ssn = 41441414; $identityAttributes->IdentityAttributes->firstName = 'John2'; $identityAttributes->IdentityAttributes->lastName = 'Doe2'; $identityAttributes->IdentityAttributes->gender = 'MALE'; $identityAttributes->IdentityAttributes->birthDate = null; try{ $identity = $client->establishIdentity($processID, $identityAttributes); //ERROR } catch (SoapFault $f){ echo "ERROR!"; } $end = $client->__soapCall('stop', array(new SoapParam($processID, 'processId')), array('soapaction' => 'C:\wsdl\BenefitDeterminationProcess_BenefitDialogueServiceSOAP\stop')); ?> Any assistance is greatly appreciated! Thanks. I've asked this question before but still haven't really figured out how best to implement it, and have found myself hitting another roadblock. I have multiple types of charts (i.e. bar, pie, etc), and various endpoints to access them. I like to keep my routing script uncluttered, and feel the following does so. $app->get('/chart', function (Request $request, Response $response) { //List of chart with optional filtering $this->chartService->index($request->getQueryParams()); return $this->chartResponder->index($response, $index); }); $app->post('/chart', function (Request $request, Response $response) { //Create a new chart of type (i.e. bar, pie, etc) specified by type parameter $chart=$this->chartService->create($request->getParsedBody()); return $this->chartResponder->create($response, $chart); }); $app->get('/chart/{id:[0-9]+}', function (Request $request, Response $response, $args) { //View chart of given ID $chart=$this->chartService->detail((int)$args['id']); return $this->chartResponder->delete($response, $chart); }); $app->delete('/chart/{id:[0-9]+}', function (Request $request, Response $response, $args) { //Delete chart of given ID $this->chartService->delete((int)$args['id']); return $this->chartResponder->delete($response, null); }); $app->post('/chart/{id:[0-9]+}/series', function (Request $request, Response $response, $args) { //Add a new series to the collection for chart with given ID $chart=$this->chartService->addSeries((int)$args['id'], $request->getParsedBody()); return $this->chartResponder->update($response, $chart); }); $app->put('/chart/{id:[0-9]+}/series/{seriesPosition:[0-9]+}', function (Request $request, Response $response, $args) { //Modify series of given position in the collection for chart with given ID $chart=$this->chartService->updateSeries((int)$args['id'], (int)$args['seriesPosition'], $request->getParsedBody()); return $this->chartResponder->update($response, $chart); }); //More endpoints for chart of given ID... I then created the following service to support the endpoints. Off topic, but is this a service or a controller? My index() method is chart type agnostic. My create() method needs a means to determine what type of chart to create, and does so using the received chart "type" passed in the body to get the applicable repository. All the other methods receive the chart ID in the URL path and use it to first get the chart entity and then get the applicable repository based on the object. All seems good! <?php namespace NotionCommotion\ChartBuilder\Service; use NotionCommotion\ChartBuilder\Entity\Chart; class ChartService { protected $em; public function __construct(\Doctrine\ORM\EntityManager $em) { $this->em = $em; } public function index(array $params=[]):array { return $this->em->getRepository(Chart::class)->index($params); } public function create(array $params):Chart { //Get the specific repo based on $params['type]. Not perfect, but good enough $discriminatorMap=$this->em->getClassMetadata(Chart::class)->discriminatorMap; $repo = $this->em->getRepository($discriminatorMap[$params['type']]); //Validate data $chart=$repo->create($params); $this->em->persist($chart); $this->em->flush(); return $chart; } public function read(int $id):Chart { return $this->em->getRepository(Chart::class)->find($id); } public function delete(int $id):void { $this->em->remove($this->read($id)); $this->em->flush(); } public function addSeries(int $idPublic, array $id):Chart { $chart=$this->read($id); //Validate data $repo=$this->em->getRepository(get_class($chart)); $repo->addSeries($chart, $params); $this->em->persist($chart); $this->em->flush(); return $chart; } public function updateSeries(int $id, int $position, array $params):Chart { $chart=$this->read($id); $series=$chart->getSeries(); $seriesNode=$series->offsetGet($position); //Validate data $repo=$this->em->getRepository(get_class($seriesNode)); $repo->update($seriesNode, $params); $this->em->persist($chart); $this->em->flush(); return $chart; } } Until... I find myself needing to put non-database related functionality in the repository and violating the single responsibility principle. I am not a complete purist and might be willing to do so, however, there does not appear to be a clean way to inject dependencies in a Doctrine repository. One thought I had was to create specialized services maybe as follows: $c['chartService'] = function ($c) { return new ChartService( $c[EntityManager::class], [ 'bar'=>function ($c) {return new BarChartService($c[EntityManager::class]);}, 'pie'=>function ($c) {return new PieChartService($c[EntityManager::class], $c['someOtherObject']);}, //add more types... ] ); };
class ChartService { protected $em, $subServices=[]; public function __construct(\Doctrine\ORM\EntityManager $em, $subServices) { $this->em = $em; $this->subServices = $subServices; } public function index(array $params=[]):array {/* no change */} public function create(array $params):Chart {/* maybe no change */} public function __call($name, $args) { $chart=$this->em->getRepository(Chart::class)->find($args[0]); $subservice=$this->getSubservice($chart); $args[0]=$chart; return $subservice->$name(...$args); } } abstract class AbstractSpecificChartService { protected $em; public function __construct(\Doctrine\ORM\EntityManager $em) { $this->em = $em; } public function __call($name, $args) { throw new \Exception("Method $name not supported"); } protected function getSubservice(Chart $chart):self { //Haven't figured out but can do so if needed. } public function delete(Chart $chart):void { //Include methods common to all charts here $this->em->remove($chart); $this->em->flush(); } protected function helperMethods($foo) { //If necessary. } } class BarChartService extends AbstractSpecificChartService { //Override __construct if necessary public function updateSeries(Chart $chart, int $position, array $params):Chart { //Note that Chart and not $id is passed. //implement code as needed return $chart; } }
So, after this long story, how should I implement this? Thank you |