Welcome to Open Discussion

2010-12-23
2013-06-06
  • victor puig
    victor puig
    2010-12-23

    Hi:
    I have a question.
    I need to create various web services but I want to create them in the same file (services.php) and call them from the other file (front.php).
    I create the first service in services.php:
    $server = new soap_server();
    $server->configureWSDL("fun1",$ns);
    $server->wsdl->schemaTargetNamespace=$ns;
    $server->register("fun1",array("x" => "xsd:string"),array("return" => "xsd:string"),$ns);
    function fun1($x){

    return new soapval("return","xsd:string",$x);
    }

    When I create the second service, only change the function name:

    $server2 = new soap_server();
    $server2->configureWSDL("fun2",$ns);
    $server2->wsdl->schemaTargetNamespace=$ns;
    $server->register("fun2",array("x" => "xsd:string"),array("return" => "xsd:string"),$ns);
    function fun2($x){

    return new soapval("return","xsd:string",$x);
    }

    And the end of file, I have this code:

    if (isset($HTTP_RAW_POST_DATA)) {
    $input = $HTTP_RAW_POST_DATA;
    }
    else {
    $input = implode("\r\n", file('php://input'));
    }
    $server->service($input);
    $server2->service($input);
    exit;

    And when I call from the client the services:

    require_once("nusoap.php");
    $wsdl="http://localhost/service.php";
    $client = new nusoap_client($wsdl);
    $param = array("amount"=>10.00,);
    echo $client->call("fun1", $param);
    echo $client->call("fun2", $param);

    In the web page, only show me the first function, the second print "Array".

    Can I have 2 web services in the same file??

    Thanks a lot for your help…

     
  • Nitesh Thakur
    Nitesh Thakur
    2012-05-03

    Hi There,

    Can anybody tell me how to add authentication header to wsdl created using nusoap