SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need simple example for Web services

    Hi all ,

    Need ur help. Im very new to web-service concept.

    Urgently i need the sample code in web-service. please that should be very simple to understand, bcoz im a beginner.

    I have to write a web-service code to know whether the given "string" from client is available on server database.

    Get the "string" from client as input. Check it out in the server side database and send the reply(output) whether it is available or not.


    The above should be done through web-service concept.

    I need a very simple example code in web-service to fulfill the above criteria.

    Please do the needful....
    Thanks in advance,

    Regards,
    Vanash

  2. #2
    SitePoint Member
    Join Date
    Apr 2010
    Location
    France - Brest
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi,

    you can have a look here

    it's a basic example of a client/server soap web service

    hope this help

  3. #3
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by LrtL View Post
    hi,

    you can have a look here

    it's a basic example of a client/server soap web service

    hope this help
    Hi LrtL,

    Thanks for ur reply..

    I tried the example that sent by u as a link.
    I got the Fatal Error, as below

    The original text : mississippi
    Fatal error: Uncaught SoapFault exception: [HTTP] Unable to parse URL in C:\wamp\www\webservices\newclient.php:10 Stack trace: #0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'newserver.php', 'urn:localhost-s...', 1, 0) #1 [internal function]: SoapClient->__call('getRot13', Array) #2 C:\wamp\www\webservices\newclient.php(10): SoapClient->getRot13('mississippi') #3 {main} thrown in C:\wamp\www\webservices\newclient.php on line 10


    I tried some other examples i got same fatal error message.
    I don't know how to fix it.

    Please help out..

    Thanks and Regards,
    Vanash

  4. #4
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    client.php

    $client = new SoapClient("stockquote.wsdl");

    try {
    print($client->getQuote("ibm"));
    }

    catch(SoapFault $e) {
    print "<pre>Exception:\n";
    print "Request :\n".htmlspecialchars($client->__getQuoteRequest()) ."\n";
    print "Response:\n".htmlspecialchars($client->__getQuoteResponse())."\n";
    print "</pre>";
    die($e);
    }


    server.php

    $quotes = array(
    "ibm" => 98.42
    );

    function getQuote($symbol) {
    global $quotes;
    return $quotes[$symbol];
    }

    ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
    $server = new SoapServer("stockquote.wsdl");
    $server->addFunction("getQuote");
    $server->handle();

    stockcode.wsdl

    <?xml version ='1.0' encoding ='UTF-8' ?>
    <definitions name='StockQuote'
    targetNamespace='http://example.org/StockQuote'
    xmlns:tns=' http://example.org/StockQuote '
    xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
    xmlnssd='http://www.w3.org/2001/XMLSchema'
    xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
    xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
    xmlns='http://schemas.xmlsoap.org/wsdl/'>

    <message name='getQuoteRequest'>
    <part name='symbol' type='xsd:string'/>
    </message>
    <message name='getQuoteResponse'>
    <part name='Result' type='xsd:float'/>
    </message>

    <portType name='StockQuotePortType'>
    <operation name='getQuote'>
    <input message='tns:getQuoteRequest'/>
    <output message='tns:getQuoteResponse'/>
    </operation>
    </portType>

    <binding name='StockQuoteBinding' type='tns:StockQuotePortType'>
    <soap:binding style='rpc'
    transport='http://schemas.xmlsoap.org/soap/http'/>
    <operation name='getQuote'>
    <soapperation soapAction='urnmethods-delayed-quotes#getQuote'/>
    <input>
    <soap:body use='encoded' namespace='urnmethods-delayed-quotes'
    encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
    </input>
    <output>
    <soap:body use='encoded' namespace='urnmethods-delayed-quotes'
    encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
    </output>
    </operation>
    </binding>

    <service name='StockQuoteService'>
    <port name='StockQuotePort' binding='StockQuoteBinding'>
    <soap:address location='http://localhost/webservices/server.php'/>
    </port>
    </service>
    </definitions>
    I tried the above example, I got the error, as below

    Exception:


    Fatal error: Uncaught SoapFault exception: [Client] Function ("__getQuoteRequest") is not a valid method for this service in C:\wamp\www\webservices\client.php:13
    Stack trace:
    #0 [internal function]: SoapClient->__call('__getQuoteReque...', Array)
    #1 C:\wamp\www\webservices\client.php(13): SoapClient->__getQuoteRequest()
    #2 {main}
    thrown in C:\wamp\www\webservices\client.php on line 13


    Please tell me how to fix this error?

    Regards,
    Vanash

  5. #5
    SitePoint Member
    Join Date
    Apr 2010
    Location
    France - Brest
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you set the "?wsdl" appendix to the URL ?

    Is the extension=php_soap.dll directive activated in the php.ini file ?

    You can test nusoap instead perhaps ?

  6. #6
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi LrtL,

    Quote Originally Posted by LrtL View Post
    Have you set the "?wsdl" appendix to the URL ?

    Is the extension=php_soap.dll directive activated in the php.ini file ?

    You can test nusoap instead perhaps ?
    Thanks for ur reply.. I tried as per ur suggestions.. but i got this error:

    Fatal error: Call to undefined method nusoap_client::getQuote() in C:\wamp\www\webservices\client.php on line 9

    Changes made in client.php

    require_once('../lib/nusoap.php');
    $client = new nusoap_client("stockquote.wsdl?wsdl");

    Is that right?

    Regards,
    Ashok

  7. #7
    SitePoint Member
    Join Date
    Apr 2010
    Location
    France - Brest
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Vanash,

    have you seen this thread ?

    It seems to be the same problem ...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •