weixin_33744141 2017-10-24 19:29 采纳率: 0%
浏览 29

Javascript调用Nusoap WS

I'me new to PHP and PHP WS's and my porpouse is to upload a image to a temp file with a GUID name and use it to share with some social media with Cordova & Facebook plugin

I Have this WS and i'm trying to call it via Ajax but still gives me this error:

Operation '' is not defined in the WSDL for this service, the objective is to upload an image (The WS is working fine, i tested with SoapUI) and upload well the Image.

SERVER.PHP

            <?php
            error_reporting(0);  
            require_once('config/nusoap.php');
            $server = new soap_server();

            $server->configureWSDL('File Transfer Using Nusoap', 'urn:fileTransferwsdl');

            $server->register('transfer_file',                                                             
                array('filename' => 'xsd:string','fileAsEndcodedString' => 'xsd:string'),
                array('return' => 'xsd:string'),
                'urn:fileTransferwsdl',                                                                 
                'urn:fileTransferwsdl#transferFile',
                'rpc',
                'encoded',
                'Transfer any file using web service'
            );
            // Define the method as a PHP function
            function transfer_file($pFilename,$pEncodedString) {                           
                        $decodedData=base64_decode($pEncodedString);
                        $fp = fopen("uplodedimages/".$pFilename, 'w');
                        fwrite($fp, $decodedData);
                        fclose($fp);
                        return 'Your file is transfer to server successfully file name is -, ' . $pFilename;
            }


            // Use the request to (try to) invoke the service
            $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
            $server->service($HTTP_RAW_POST_DATA);
            $server->register("transfer_file");
            //$server->service(file_get_contents("php://input"));
            ?> 

AJAX METHOD

    var soapRequest;
    try {
        soapRequest = "<soapenv:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:urn='urn:fileTransferwsdl'>< soapenv:Header/>< soapenv:Body><urn:transfer_file soapenv:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'><filename xsi:type='xsd:string'>" + filename + "</filename><fileAsEndcodedString xsi:type='xsd:string'>" + fileasString + "</fileAsEndcodedString></urn: transfer_file ></soapenv: Body ></soapenv: Envelope >";
        console.log("callWS2");

        $.ajax({
            type: "POST",
            url: wsUrl, //http://localhost/server.php
            contentType: "xml",
            dataType: "xml",
            data: soapRequest,
            success: succeeded,
            error: queryError
        });

Is the Request Wrong or ContentType? Thank you for the help

  • 写回答

1条回答 默认 最新

  • weixin_33698823 2017-10-24 22:21
    关注

    After some digging I found the problem.

    1st: the Request have some spaces

    2sd: I Found a connection problem with the Content-Security-Policy so i add this exception: default-src 'self' data: gap: https://ssl.gstatic.com http://myWebserviceSite.com/;

    3rd: change this contentType: "xml",dataType: "xml" to this contentType: "text/xml", dataType: "text/xml";

    And is all working on cordova and browser =)

    评论

报告相同问题?