[Solved] Can not load WSDL file?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

[Solved] Can not load WSDL file?

Post by phpcoder »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,
I am trying to run a simple example. I cant load WSDL file. Following is my code:
WSDL file
dotNet.wsdl
[syntax="xml"]
<?xml version="1.0"?>
<definitions name="NetPuzzle" targetNamespace="urn:NetPuzzle" xmlns:
typens="urn:NetPuzzle" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:
soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.
xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
</definitions> 
<message name="getPuzzle">
<part name="difficulty" type="xsd:int" />
</message>
<message name="getPuzzleResponse">
<part name="return" type="string" />
</message>
<portType name="NetPuzzlePort">
<operation name="getPuzzle">
<input message="typens:getPuzzle" />
<output message="typens:getPuzzleResponse" />
</operation>
</portType>
<binding name="NetPuzzleBinding" type="typens:NetPuzzlePort">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="getPuzzle">
<soap:operation soapAction="urn:NetPuzzleAction" />
<input>
<soap:body use="encoded" namespace="urn:NetPuzzle"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="urn:NetPuzzle"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
</binding>
<service name="NetPuzzleService">
<port name="NetPuzzlePort" binding="typens:NetPuzzleBinding">
<soap:address location="http://localhost/server.php" />
</port>
</service>
Client.php[/syntax]

Code: Select all

<?php
$soap = new SoapClient('http://localhost/dotNet.wsdl');
echo $soap->getPuzzle("1");
?>
server.php

Code: Select all

<?php
function getPuzzle($difficulty) {
$puzzles[1][] = “What is the best web mag in the world?”;
$puzzles[2][] = “What is the air-speed velocity of an unladen swallow?”;
$puzzles[3][] = “What is the meaning of life?”;
$randpuz = array_rand($puzzles[$difficulty]);
return $puzzles[$difficulty][$randpuz];
}
$server = new SoapServer(“dotnet1.wsdl”);
$server->addFunction(“getPuzzle”);
$server->handle();
?>
When I try to run this example I got followibng error:

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://localhost/dotNet.wsdl' in C:\wamp\www\client.php:2 Stack trace: #0 C:\wamp\www\client.php(2): SoapClient->SoapClient('http://localhos...') #1 {main} thrown in C:\wamp\www\client.php on line 2

Help me.
Thanks


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by phpcoder on Tue Jul 17, 2007 7:57 am, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

xmlns:
typens
should be xmlns:typens, same with xmlns:soap and xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/".
Why do you close the definitions element immediately? Move </definitions> to the end of the document.
Who or what created this wsdl file?
User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

Post by phpcoder »

volka wrote:
xmlns:
typens
should be xmlns:typens, same with xmlns:soap and xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/".
Why do you close the definitions element immediately? Move </definitions> to the end of the document.
Who or what created this wsdl file?
thanks for you help. Now I am getting this error:

Fatal error: Uncaught SoapFault exception: [Client] looks like we got no XML document in C:\wamp\www\client.php:3 Stack trace: #0 [internal function]: SoapClient->__call('getPuzzle', Array) #1 C:\wamp\www\client.php(3): SoapClient->getPuzzle(1) #2 {main} thrown in C:\wamp\www\client.php on line 3
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Open the wsdl file in your browser. What error message do you get?
User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

Post by phpcoder »

volka wrote:Open the wsdl file in your browser. What error message do you get?
I am not getting any error messages. It just displays the wsdl file
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Ah ok, the script is already calling the method. But the soap server doesn't send a valid response. Let's take a look at the response.

Code: Select all

<?php
class SoapClientDebug extends SoapClient {
  public function __doRequest($request, $location, $action, $version) {
    echo '<pre>request: ', htmlentities($request), "\n</pre>\n";
    $response = parrent::__doRequest($request, $location, $action, $version);
    echo '<pre>response: ', htmlentities($response), "\n</pre>\n";
    return $response;
  }
}

$soap = new SoapClientDebug('http://localhost/dotNet.wsdl');
echo $soap->getPuzzle("1");
?>
User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

Post by phpcoder »

volka wrote:Ah ok, the script is already calling the method. But the soap server doesn't send a valid response. Let's take a look at the response.

Code: Select all

<?php
class SoapClientDebug extends SoapClient {
  public function __doRequest($request, $location, $action, $version) {
    echo '<pre>request: ', htmlentities($request), "\n</pre>\n";
    $response = parrent::__doRequest($request, $location, $action, $version);
    echo '<pre>response: ', htmlentities($response), "\n</pre>\n";
    return $response;
  }
}

$soap = new SoapClientDebug('http://localhost/dotNet.wsdl');
echo $soap->getPuzzle("1");
?>

I have tried the above code. I got these errors.

request: <?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:NetPuzzle" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encodin ... difficulty xsi:type="xsd:int">1</difficulty></ns1:getPuzzle></SOAP-ENV:Body></SOAP-ENV:Envelope>



Fatal error: Uncaught SoapFault exception: [Client] Class 'parrent' not found in C:\wamp\www\client.php:5 Stack trace: #0 C:\wamp\www\client.php(5): SoapClientDebug::__doRequest() #1 [internal function]: SoapClientDebug->__doRequest('<?xml version="...', 'http://192.168....', 'urn:NetPuzzleAc...', 1, 0) #2 [internal function]: SoapClient->__call('getPuzzle', Array) #3 C:\wamp\www\client.php(12): SoapClientDebug->getPuzzle('1') #4 {main} thrown in C:\wamp\www\client.php on line 5

(Sorry I am new to this soap stuff).
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

I guess it must be parent
User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

Post by phpcoder »

dude81 wrote:I guess it must be parent
I changed it to parent now I got these errors:

request: <?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:NetPuzzle" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encodin ... difficulty xsi:type="xsd:int">1</difficulty></ns1:getPuzzle></SOAP-ENV:Body></SOAP-ENV:Envelope>


response: <br />
<b>Parse error</b>: syntax error, unexpected $end in <b>C:\wamp\www\server.php</b> on line <b>10</b><br />



Fatal error: Uncaught SoapFault exception: [Client] looks like we got no XML document in C:\wamp\www\client.php:12 Stack trace: #0 [internal function]: SoapClient->__call('getPuzzle', Array) #1 C:\wamp\www\client.php(12): SoapClientDebug->getPuzzle('1') #2 {main} thrown in C:\wamp\www\client.php on line 12
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

phpcoder wrote:response: <br />
<b>Parse error</b>: syntax error, unexpected $end in <b>C:\wamp\www\server.php</b> on line <b>10</b>
There's a syntax error in your server.php
User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

Post by phpcoder »

volka wrote:
phpcoder wrote:response: <br />
<b>Parse error</b>: syntax error, unexpected $end in <b>C:\wamp\www\server.php</b> on line <b>10</b>
There's a syntax error in your server.php
Yeah it says there is an syntax error. But I have simple server.php file and I cant see any error in that file . Please check my server file and tell me whats the error
Server.php

Code: Select all

<?php

function getPuzzle($difficulty) {
$puzzles = "What is the best web mag in the world?";

return $puzzles;
}
$server = new SoapServer("http://192.168.1.55/dotNet.wsdl");
$server->addFunction("getPuzzle”);
$server->handle();
?>
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

Look at this carefully

Code: Select all

$server->addFunction("getPuzzle”);
Looks like there is spoon feeding going here.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

phpcoder wrote:$server->addFunction("getPuzzle”)
replace ” by "
User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

Post by phpcoder »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


[quote="volka"][quote="phpcoder"]$server->addFunction("getPuzzle”)[/quote]replace ” by "[/quote]
Now I am getting this error :

request: [syntax="xml"]<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:NetPuzzle" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:getPuzzle><difficulty xsi:type="xsd:int">1</difficulty></ns1:getPuzzle></SOAP-ENV:Body></SOAP-ENV:Envelope>

response:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:NetPuzzle" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:getPuzzleResponse><return xsi:type="xsd:string">What is the best web mag in the world?</return></ns1:getPuzzleResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>


Fatal error: Uncaught SoapFault exception: [Client] looks like we got no XML document in C:\wamp\www\client.php:12 Stack trace: #0 [internal function]: SoapClient->__call('getPuzzle', Array) #1 C:\wamp\www\client.php(12): SoapClientDebug->getPuzzle('1') #2 {main} thrown in C:\wamp\www\client.php on line 12

I am sorry I am anoying you but as I told you I am new to soap and xml.
Thanks


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

What is adding this
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>
html document skeleton? Did you post the entire server.php?
Post Reply