473,398 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 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 10230
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 windows applications done in VB.NET. what have i...
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 webservice end point URL basically consists of a base...
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 scenarioes of loggin that are common enough to share a...
5
by: Stephanie Stowe | last post by:
Imagine that I had this <webServices> <soapExtensionTypes> <add type="Microsoft.Web.Services.WebServicesExtension, Microsoft.Web.Services, Version=1.0.0.0, Culture=neutral,...
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 normal classes. The way we are invoking methods in...
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 IIS locally on the development boxes. Can you...
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 some miscellaneous details for the contact, in a...
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 works time and time again perfectly. When I include...
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 Vb.net. We use pessimistic Locking due to...
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 moving a part of their operations into a second...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.