472,353 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

webservices in php

Ciary
247 Expert 100+
good morning/afternoon/evening/night fellow coders,

like a few times before i'm stuck with a problem. this time it hes everything to do with webservices or WCF.
in the end, i want to convert an xml/access/SQL database (depends on what the user uploads) to a simple multi-dimentional array.
but it isn't what i was trying to do now since i'm rather new to WCF. so, i started with a simple 'hello world'

coding the webservice wasn't difficult, but now i tried to use it in php using the next code:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. header('Content-Type: text/plain');
  3.  
  4. echo "WCF Test\n";
  5.  
  6. $client = new SoapClient('webservice try 1/webservice try 1/Service1.svc?wsdl');
  7.  
  8. $retval = $client->Test();
  9.  
  10. echo $retval;
  11. ?>
like you could have guessed. this didnt work. i got the next error:

-------------------------------------------------------------------------------------------------------------------
WCF Test
<br />
<b>Warning</b>: SoapClient::SoapClient() [<a href='soapclient.soapclient'>soapclient.soapclient </a>]: I/O warning : failed to load external entity &quot;webservice try 1/webservice try 1/Service1.svc?wsdl&quot; in <b>C:\xampp\htdocs\page\testWCF.php</b> on line <b>6</b><br />
<br />
<b>Fatal error</b>: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'webservice try 1/webservice try 1/Service1.svc?wsdl' : failed to load external entity &quot;webservice try 1/webservice try 1/Service1.svc?wsdl&quot;
in C:\xampp\htdocs\page\testWCF.php:6
Stack trace:
#0 C:\xampp\htdocs\page\testWCF.php(6): SoapClient-&gt;SoapClient('webservice try ...')
#1 {main}
thrown in <b>C:\xampp\htdocs\page\testWCF.php</b> on line <b>6</b><br />
-------------------------------------------------------------------------------------------------------------------

can anyone tell me how this should be done properly?
Apr 15 '09 #1
18 10055
Ciary
247 Expert 100+
problem solved. my url was wrong.

but now i have a new problem. 'Unsupported Media Type' on line 8

does anyone know how i can fix this?
Apr 15 '09 #2
Dormilich
8,658 Expert Mod 8TB
shouldn't be the media type of a SOAP request be "text/xml" or "application/soap+xml"?
Apr 15 '09 #3
Ciary
247 Expert 100+
if you mean that i need to change my header information, i tried that and it didn't work. also, i can connect to my web service since i can var_dump my functions:
Expand|Select|Wrap|Line Numbers
  1. var_dump($client->__getFunctions());
result:
-------------------------------------------------------------------------------------------------------------------
array(3) {
[0]=>
string(44) "GetDataResponse GetData(GetData $parameters)"
[1]=>
string(95) "GetDataUsingDataContractResponse GetDataUsingDataContract(GetDataUsingDataContract $parameters)"
[2]=>
string(35) "TestResponse Test(Test $parameters)"
}
-------------------------------------------------------------------------------------------------------------------

but asking it to execute a function still doesn't work. even if it doesn't need parameters.

i don't know what you or the error mean by 'media type'. and i dont know how i can change it either.
Apr 15 '09 #4
Dormilich
8,658 Expert Mod 8TB
according to the manual, you call a soap function vial SoapClient::__soapCall()
Apr 15 '09 #5
Ciary
247 Expert 100+
i know, but one of the examples on the bottom of the page says otherwise.

anyway, here is the code i tried (with __call) but it still gives the same error.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. header('Content-Type: text/plain');
  3.  
  4. echo "WCF Test\n";
  5.  
  6. $client = new SoapClient('http://localhost:2024/Service1.svc?wsdl');
  7.  
  8. var_dump($client->__getFunctions());
  9.  
  10. $empty = array();
  11.  
  12. $webService = $client->__soapCall('Test', $empty);
  13. ?>
i also tried __call but it doesnt work either.
Apr 15 '09 #6
Dormilich
8,658 Expert Mod 8TB
where exactly does the function fail? is there any specific reasons given in the error message?
Apr 15 '09 #7
Ciary
247 Expert 100+
this is the full error message. i cant tell you more then this since i dont know it either. the functions i'm using are standard functions provided by visual studio 2008. i wrote the test function myself but i tried everything with both test and getData.

error message:
-------------------------------------------------------------
<br />
<b>Fatal error</b>: Uncaught SoapFault exception: [HTTP] Unsupported Media Type in C:\xampp\htdocs\page\testWCF.php:12
Stack trace:
#0 [internal function]: SoapClient-&gt;__doRequest('&lt;?xml version=&quot;...', 'http://localhos...', 'http://tempuri....', 1, 0)
#1 C:\xampp\htdocs\page\testWCF.php(12): SoapClient-&gt;__soapCall('Test', Array)
#2 {main}
thrown in <b>C:\xampp\htdocs\page\testWCF.php</b> on line <b>12</b><br />
---------------------------------------------------------------
Apr 15 '09 #8
Dormilich
8,658 Expert Mod 8TB
I can only guess, but it seems like the soap message transfer (HTTP) uses an inappropriate media type, there should be a documentation somewhere which states what media types are accepted by the soap recipient.

maybe the SoapVar class can help you. also read the comments in PHP's SOAP manual, maybe you find useful information there.
Apr 15 '09 #9
Ciary
247 Expert 100+
a new day and still stuck with the same problem.

like you already said. by media type they mean "application/soap + xml" but i've no idea how i could change this. the soapvar class has nothing to do with this. its just a better way to send data along with my soapcall.

can you tell me how i can change my mediatype?

edit: the next info could be more helpful:
when i used this code(see codeblock1) the connection simply times out instead of causing an error. when i tried it with 1(see codeblock2) it gave the same error as before.

cb1:
Expand|Select|Wrap|Line Numbers
  1. $wsdl_url =  "http://localhost:2024/Service1.svc?wsdl";
  2. $options = array('soap_version'   => SOAP_1_2);            //added this!!
  3. $client     = new SoapClient($wsdl_url, $options);
  4.  
  5. $params=array('value'=>'1');
  6.  
  7. try{
  8.     print_r($client->Test());
  9. }catch(SoapFault $fault){
  10.         echo ' Error Message : ',
  11.         $fault->getMessage(); 
  12. }
cb2:
Expand|Select|Wrap|Line Numbers
  1. $wsdl_url =  "http://localhost:2024/Service1.svc?wsdl";
  2. $options = array('soap_version'   => SOAP_1_1);            //changed this!!
  3. $client     = new SoapClient($wsdl_url, $options);
  4.  
  5. $params=array('value'=>'1');
  6.  
  7. try{
  8.     print_r($client->Test());
  9. }catch(SoapFault $fault){
  10.         echo ' Error Message : ',
  11.         $fault->getMessage(); 
  12. }
Apr 16 '09 #10
Ciary
247 Expert 100+
ok, i got my problem solved. it wasnt a problem of php but a problem in my webservice.

i needed to change my web.config. in it, the binding as standard set to wsHttpBinding, but php5 doesnt support this yet. therefore you need to change it to basicHttpBinding. dont really know whats different but i do know it works.

ty for your help Dormilich. i would have given up without you :)
Apr 16 '09 #11
Dormilich
8,658 Expert Mod 8TB
given that I've never dealt with WSDL before, this is a great achievement (of you). now I know someone whom I can ask if I should try it myself *g*.
Apr 16 '09 #12
Ciary
247 Expert 100+
if you need it, just ask and ill see what i can do to answer :) i've only echoed 'hello world' and a send parameter so far but it looks really simple. all code in the webservice is standard vb.net code so it isn't that difficult either.

now lets see if i can transfer files ^^
Apr 16 '09 #13
Dormilich
8,658 Expert Mod 8TB
I recommend curl, wsdl is not designed for file transfer (well, if you mean pure file transfer).

PS: can't use vb.net, I've got a unix server
Apr 16 '09 #14
Ciary
247 Expert 100+
problem is that it's a file transfer thats going to be used in my webservice. the whole reason for using a webservice is because i want to convert an uploaded access/xml or SQL database to a simple array which i can use in my website.

i'll find a way to get it working :)

for helping you with webservices, building one in php/c/java isnt difficult either you only have a few lines to declare it's a webservice and not a stand-alone program. i'm not sure about c but i know the other 2 are compatible with Unix.if you need programming any of those (apart from php since i think you might be able to) i'll be glad to help.
Apr 16 '09 #15
Dormilich
8,658 Expert Mod 8TB
converting an XML file into an array can be achieved by deserialization

XML ==(XSLT)=> WDDX ==(wddx_deserialize())=> PHP array

(though there are certainly more possibilities)
Apr 16 '09 #16
Ciary
247 Expert 100+
i know, xml isnt the problem. even SQL shouldnt be that hard. it's access thats causing the trouble. dont know how that could be converted using only php.
Apr 16 '09 #17
Dormilich
8,658 Expert Mod 8TB
sorry, can't help there since I don't know anything about access.
Apr 16 '09 #18
Ciary
247 Expert 100+
i just found a way: first make a function in which you create a file using exacly the same one as the uploaded file. then put read the uploaded file in php using 'fopen()', 'fread()' and 'fclose()' and put it in a variable. after that, you just send the string in a second function which it writes back into the file.

another option i just found to dynamically select a database is the use of odbc with a connection string. it makes it possible to connect to an access database without the problem of needing a DSN(data source name) but if i have questions using this, ill post them in another topic since it has nothing to do with webservices.
Apr 17 '09 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jinashe | last post by:
what do i need to enable accessing of webservices from a clients PC i'm hosting some webservices from my server in VB.NET. i've got some client...
0
by: Erik P. Vinther | last post by:
Hi This might be slightly OT, but I couldn't find a better NG for this question The question is regarding versioning of webservices. A...
8
by: Allan Ebdrup | last post by:
I just had a discussion with one of my fellow programmers. We have a class for doing some logging and sending an email, it has 5 different...
5
by: Stephanie Stowe | last post by:
Imagine that I had this <webServices> <soapExtensionTypes> <add type="Microsoft.Web.Services.WebServicesExtension, Microsoft.Web.Services,...
1
by: Diffident | last post by:
Hello Guys, I have a question with regards to the efficiency and best practices in .NET framework. We are currently using Webservices as...
5
by: cyberstrike | last post by:
Hi guys, my company was wondering if it's possible to develop ASP.NET/Webservices easily using a IIS installed on a server instead of installing...
2
by: Antuane | last post by:
any one have any idea how transactions could be enabled in webservices. i.e., suppose i've got 2 methods - one to add a contact, & the other to set...
1
by: Mike | last post by:
Hi all, I have written a webservice which I am using in my smartphone applicaiton. I have tried the webservice with a WinForms client and it...
8
by: Komandur Kannan | last post by:
We have a smart device application running on handhelds(Symbol MC9000G). The backend is Oracle and a middle tier web services development done in...
5
by: ChrisM | last post by:
Hi, I have written a stand alone WinForms application with an MS Access back-end for the (small)company I work for. They are now talking about...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.