CodeIgniter Forums

Full Version: Sending WSDL file via SOAP
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
(04-29-2015, 12:01 AM)algenza Wrote: [ -> ]
(04-28-2015, 11:30 PM)ardavan Wrote: [ -> ]Yes Im getting this wsdl data


Code:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 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/" xmlns:tns="http://localhost/interface/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://localhost/interface/">
<types>
<xsd:schema targetNamespace="http://localhost/interface/">
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/>
</xsd:schema>
</types>
<message name="Master.fruitsRequest">
<part name="count" type="xsd:integer"/>
<part name="type" type="xsd:string"/>
</message>
<message name="Master.fruitsResponse">
<part name="fruit" type="xsd:string"/>
</message>
<portType name="SOAPPortType">
<operation name="Master.fruits">
<documentation>Fruit Types</documentation>
<input message="tns:Master.fruitsRequest"/>
<output message="tns:Master.fruitsResponse"/>
</operation>
</portType>
<binding name="SOAPBinding" type="tns:SOAPPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="Master.fruits">
<soap:operation soapAction="urn:http://localhost/interface//fruits" style="rpc"/>
<input>
<soap:body use="encoded" namespace="urn:SOAPServerWSDL" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="urn:SOAPServerWSDL" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="SOAP">
<port name="SOAPPort" binding="tns:SOAPBinding">
<soap:address location="http://localhost/interface/index.php/interface/nusoapserver"/>
</port>
</service>
</definitions>
url that generate this wsdl

This is the link of generating that XML
Code:
http://localhost/interface/index.php/interface/nusoapserver?wsdl

When i put this inside this my apache port will goes on +324 million ports.!!
you have to separate your soap client and soap server application or at least put them on different controller
Ok ive created a new controller for my client and i called that controllers/Client.php
And ive paste the client funtion from my nusoapserver controller to client controller.


PHP Code:
<?php
class Client extends CI_Controller{
    function 
client(){
        
$this->client = new nusoap_client(base_url()."/index.php/interface/nusoapserver?wsdl"true);

        
$this->load->view("client");
    }


How about now?
Ok this is my soap server:
PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Mysoapserver extends CI_Controller {

    public function 
index(){
 
       $this->load->library('soap');

 
       $ns="http://localhost:85/apiserver/mysoapserver";
 
       
        $server
=new nusoap_server 

        $server
->configureWSDL('MyService',$ns);

 
       $server->wsdl->schemaTargetNamespace=$ns;

 
       $input_array = array ('count' => 'xsd:integer''type' => "xsd:string"); // method parameters
 
       $return_array = array ("fruit" => "xsd:string");

 
       ##register function
 
       $server->register(
 
           'fruits'
 
           $input_array
 
           $return_array
 
           "urn:SOAPServerWSDL"
 
           "urn:".$ns."/fruits"
 
           "rpc"
 
           "encoded"
 
           "Fruit Types"
 
       );

 
       ##function that will do the job
 
       function fruits($count,$type){
 
           switch($type){
 
           case 'red':
 
               return $count." Apple";
 
               break;
 
           case 'yellow':
 
               return $count." banana";
 
               break               
            
}
 
       }

 
       $server->service(file_get_contents("php://input"));
 
   }


and this is my soap client
PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class 
Mysoapclient extends CI_Controller {

    function 
index(){
        
##load the library
        
$this->load->library('soap');
        
##initialize soap client
        
$client=new nusoap_client("http://localhost:85/apiserver/mysoapserver");
        
##client call server function and get the response
        
$response=$client->call('fruits',array("count" => 4"type" => "red"));
        
##if no error then you can view server response
        
echo $response;
    }


if you call the client url then it will show '4 Apple'.
Cool,Thanks for it. But still i need to know how to get my details instead of '4 Apple'.

I was trying to create a sample WSDL file to request and response. could you help me in this also?

Thanks
define complex type that match your query result in your wsdl
(05-05-2015, 01:36 AM)algenza Wrote: [ -> ]define complex type that match your query result in your wsdl

Thanks, it works finally.
I just needed to assign the exact tag's names.
good to know it works Smile
(05-17-2015, 07:13 PM)algenza Wrote: [ -> ]good to know it works Smile
Im not too happy because it was only client side. I could only receive the data.
Now i wanna send some data to some client.

im using your code which is you answered to me.
I cant see any '4 Apple' on my browser and the result from Client link is:

Code:
Constructor error

SOAP-ENV:Client: Operation 'fruits' is not defined in the WSDL for this service
Request

POST /backfill/index.php/interface/nusoapserver/server?wsdl HTTP/1.0
Host: localhost
User-Agent: NuSOAP/0.9.5 (1.123)
Content-Type: text/xml; charset=ISO-8859-1
SOAPAction: ""
Content-Length: 535

<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 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:Body><ns7923:fruits xmlns:ns7923="http://tempuri.org"><count xsi:type="xsd:int">4</count><type xsi:type="xsd:string">red</type></ns7923:fruits></SOAP-ENV:Body></SOAP-ENV:Envelope>
Response

HTTP/1.0 500 Internal Server Error
Date: Thu, 21 May 2015 06:50:24 GMT
Server: Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.5.19
X-Powered-By: PHP/5.5.19
Set-Cookie: ci_session=dd10680820baf510a3102ce971f83a344746f4f1; expires=Thu, 21-May-2015 08:50:24 GMT; Max-Age=7200; path=/; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Status: 500 Internal Server Error
X-SOAP-Server: NuSOAP/0.9.5 (1.123)
Content-Length: 706
Connection: close
Content-Type: text/xml; charset=ISO-8859-1

<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
 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:Body><SOAP-ENV:Fault><faultcode xsi:type="xsd:string">SOAP-ENV:Client</faultcode><faultactor xsi:type="xsd:string"></faultactor><faultstring xsi:type="xsd:string">Operation &apos;fruits&apos; is not defined in the WSDL for this service</faultstring><detail xsi:type="xsd:string"></detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
Debug

2015-05-21 08:50:24.356595 nusoap_client: ctor wsdl= timeout=0 response_timeout=30
endpoint=string(70) "http://localhost/backfill/index.php/interface/nusoapserver/server?wsdl"
2015-05-21 08:50:24.356595 nusoap_client: instantiate SOAP with endpoint at http://localhost/backfill/index.php/interface/nusoapserver/server?wsdl
2015-05-21 08:50:24.356595 nusoap_client: call: operation=fruits, namespace=http://tempuri.org, soapAction=, rpcParams=, style=rpc, use=encoded, endpointType=soap
params=array(2) {
 ["count"]=>
 int(4)
 ["type"]=>
 string(3) "red"
}
headers=bool(false)
2015-05-21 08:50:24.356595 nusoap_client: serializing param array for operation fruits
2015-05-21 08:50:24.356595 nusoap_client: in serialize_val: name=count, type=, name_ns=, type_ns=, use=encoded, soapval=
value=int(4)
attributes=bool(false)
2015-05-21 08:50:24.356595 nusoap_client: serialize_val: serialize int
2015-05-21 08:50:24.356595 nusoap_client: serialize_val returning <count xsi:type="xsd:int">4</count>
2015-05-21 08:50:24.356595 nusoap_client: in serialize_val: name=type, type=, name_ns=, type_ns=, use=encoded, soapval=
value=string(3) "red"
attributes=bool(false)
2015-05-21 08:50:24.356595 nusoap_client: serialize_val: serialize string
2015-05-21 08:50:24.356595 nusoap_client: serialize_val returning <type xsi:type="xsd:string">red</type>
2015-05-21 08:50:24.357595 nusoap_client: wrapping RPC request with encoded method element
2015-05-21 08:50:24.357595 nusoap_client: In serializeEnvelope length=138 body (max 1000 characters)=<ns7923:fruits xmlns:ns7923="http://tempuri.org"><count xsi:type="xsd:int">4</count><type xsi:type="xsd:string">red</type></ns7923:fruits> style=rpc use=encoded encodingStyle=http://schemas.xmlsoap.org/soap/encoding/
2015-05-21 08:50:24.357595 nusoap_client: headers:
bool(false)
2015-05-21 08:50:24.357595 nusoap_client: namespaces:
AND MANY MORE

Whats the problem here? i changed the ns and client link for several times. still its same
UPDATE: in the client function code i just put fruits instead of fruit.
Now It works.


Question:
I need to get the data from my DB. We assume i got all the rows and put inside rows[].
Now how can i replace with:

PHP Code:
##function that will do the job
 
       function BigData($count,$type){
 
           switch($type){
 
           case 'red':
 
               return $count." Apple";
 
               break;
 
           case 'yellow':
 
               return $count." banana";
 
               break               
            
}
 
       
Pages: 1 2