สอบถาม ComplexType NuSoap

สำหรับผู้ที่ เริ่มต้น Programming - PHP มีอะไร แนะนำ หรือข้อสงสัยต้องบอร์ด นี้ คนที่มีความรู้ แบ่งปันคนอื่นบ้างนะ ปัญหาการเขียนโปรแกรม แบบ OOP Session Cookies php network

Moderator: mindphp, ผู้ดูแลกระดาน

touleg
PHP Super Member
PHP Super Member
โพสต์: 480
ลงทะเบียนเมื่อ: 25/01/2010 11:57 pm
ติดต่อ:

สอบถาม ComplexType NuSoap

โพสต์ที่ยังไม่ได้อ่าน โดย touleg »

ผมอยากปรึกษาคุณ mindphp หรือผู้ที่มีความรู้ Soap นะครับ

จาก
<OTA_HotelAvailNotifRQ xmlns="http://www.opentravel.org/OTA/2003/05" Version="1.0" TimeStamp="2005-08-01T09:30:47+08:00">
<AvailStatusMessages HotelCode="HOTEL">
<AvailStatusMessage BookingLimit="10">
<StatusApplicationControl Start="2010-01-01" End="2010-01-14" InvTypeCode="A1K" RatePlanCode="GLD"/>
</AvailStatusMessage>
</AvailStatusMessages>
</OTA_HotelAvailNotifRQ>

ผมจะเขียน ComplexType ออกมาได้ยังไงครับ เข้าใจว่าคิดให้เหมือนกับโครงสร้าง Array แต่ยังไม่ค่อยเข้าใจโครงสร้างที่จะไปเขียนลง ComplexType พอดียังไม่ค่อยเข้าใจการสร้างสักเท่าไร มันยังมีแบบนี้ที่ต้องทำอีกหลายแบบ คิดว่าถ้าได้ตรงนี้เป็นตัวอย่าง ก็น่าจะเข้าใจสามารถเอาไปทำต่อที่เหลือเองได้ครับ

ใช้ nusoap นะครับ

ขอบคุณล่วงหน้าครับ
ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41230
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

Re: สอบถาม ComplexType NuSoap

โพสต์ที่ยังไม่ได้อ่าน โดย mindphp »

จะทำเป็น webservice ให้คนอื่นเข้ามาใช้งาน หรอครับ
Nusoap มันเป็น lib เก่ามากเลยนะครับ
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
touleg
PHP Super Member
PHP Super Member
โพสต์: 480
ลงทะเบียนเมื่อ: 25/01/2010 11:57 pm
ติดต่อ:

Re: สอบถาม ComplexType NuSoap

โพสต์ที่ยังไม่ได้อ่าน โดย touleg »

แล้วปัจจุบันใช้อะไรหรอครับ
ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41230
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

Re: สอบถาม ComplexType NuSoap

โพสต์ที่ยังไม่ได้อ่าน โดย mindphp »

ใช้ phpSoap เลยครับ
สำหรับ php5 เปิด เค้า build มาใช้ทั้ง Client และ Server แล้วครับ
Soap Client enabled
Soap Server enabled

หรือไม่ก็ ZendSoap ตัว ZendSoap ก็น่าสนใจดีครับ
http://framework.zend.com/manual/1.12/e ... erver.html

ปล. แต่โปรเจคผมก่อนหน้านี้ก็ NuSoap ครับ ง่ะๆ
แต่ไม่อยากแนะนำให้ใช้เพราะมันเก่าถ้ามีปัญหาตัว lib ก็ไม่ได้อัพเดดมานานแล้ว
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
touleg
PHP Super Member
PHP Super Member
โพสต์: 480
ลงทะเบียนเมื่อ: 25/01/2010 11:57 pm
ติดต่อ:

Re: สอบถาม ComplexType NuSoap

โพสต์ที่ยังไม่ได้อ่าน โดย touleg »

mindphp เขียน:ใช้ phpSoap เลยครับ
สำหรับ php5 เปิด เค้า build มาใช้ทั้ง Client และ Server แล้วครับ
Soap Client enabled
Soap Server enabled

หรือไม่ก็ ZendSoap ตัว ZendSoap ก็น่าสนใจดีครับ
http://framework.zend.com/manual/1.12/e ... erver.html

ปล. แต่โปรเจคผมก่อนหน้านี้ก็ NuSoap ครับ ง่ะๆ
แต่ไม่อยากแนะนำให้ใช้เพราะมันเก่าถ้ามีปัญหาตัว lib ก็ไม่ได้อัพเดดมานานแล้ว
ขอบคุณครับ ตอนนี้ผมไปเขียน Manual เองละ 555 ใช้งานได้เวิคดีครับ ถ้าจะใช้พวกนี้คงต้องใช้เวลานั่งงมกับมันสักพัก แต่นี้งานมันเร่ง เลยไม่มีเวลามานั่งศึกษา ตอนนี้ก็ถืองานคนเดียว 3-4 Project ไม่ไหวๆ ไม่ค่อยได้หลับได้นอนเท่าไร
ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41230
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

Re: สอบถาม ComplexType NuSoap

โพสต์ที่ยังไม่ได้อ่าน โดย mindphp »

เผื่อท่านอื่นเข้ามา อ่านจะได้เก็บไว้เป็นความรู้

โค้ด: เลือกทั้งหมด

<?php

    class ResponseObject {
        public $responseCode = 0;
        public $responseMessage = 'Unknown error!';
        public $stuffArray = NULL;
    }   

    /**
     * @return object
     */ 
    function getStuffs( $user='', $pass='' ) {

        $responseObject = new ResponseObject();

        // check stuffs in a simple way now
        if( !($user == 'someone' and $pass == '1234') ){
            $responseObject->responseCode = 2;
            $responseObject->responseMessage = 'Authentication failed!';
            return $responseObject;
        }

        $responseObject->stuffArray   = array();
        $responseObject->stuffArray[] = array( 'id'=>122, 'name'=>'One stuff');
        $responseObject->stuffArray[] = array( 'id'=>213, 'name'=>'Another stuff');
        $responseObject->stuffArray[] = array( 'id'=>435, 'name'=>'Whatever stuff');
        $responseObject->stuffArray[] = array( 'id'=>65, 'name'=>'Cool Stuff');
        $responseObject->stuffArray[] = array( 'id'=>92, 'name'=>'Wow, what a stuff');          

        $responseObject->responseCode = 1;
        $responseObject->responseMessage = 'Successful!';
        return $responseObject; 
    }

    require_once 'nusoap/lib/nusoap.php';
    $server = new soap_server;

    // $myNamespace = $_SERVER['SCRIPT_URI'];
    $myNamespace = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];

    $server->configureWSDL(
        // string $serviceName, name of the service
        'MyStuffService',
        // mixed $namespace optional 'tns' service namespace or false
        // 'urn:' . $myNamespace
        $myNamespace
    );

    // $server->wsdl->schemaTargetNamespace = 'http://soapinterop.org/xsd/';
    $server->wsdl->schemaTargetNamespace = $myNamespace;

    $server->wsdl->addComplexType(
        // name
        'Stuffs',
        // typeClass (complexType|simpleType|attribute)
        'complexType',
        // phpType: currently supported are array and struct (php assoc array)
        'struct',
        // compositor (all|sequence|choice)
        'all',
        // restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
        '',
        // elements = array ( name = array(name=>'',type=>'') )
        array(
            'id' => array(
                'name' => 'id',
                'type' => 'xsd:int'
            ),
            'name' => array(
                'name' => 'name',
                'type' => 'xsd:string'
            )
        )
    );  

    $server->wsdl->addComplexType(
        // name
        'StuffsArray',
        // typeClass (complexType|simpleType|attribute)
        'complexType',
        // phpType: currently supported are array and struct (php assoc array)
        'array',
        // compositor (all|sequence|choice)
        '',
        // restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
        'SOAP-ENC:Array',
        // elements = array ( name = array(name=>'',type=>'') )
        array(),
        // attrs
        array(
            array(
                'ref' => 'SOAP-ENC:arrayType',
                'wsdl:arrayType' => 'tns:Stuffs[]'
            )
        ),
        // arrayType: namespace:name (http://www.w3.org/2001/XMLSchema:string)
        'tns:Stuffs'
    );


    $server->wsdl->addComplexType(
        // name
        'ResponseObject',
        // typeClass (complexType|simpleType|attribute)
        'complexType',
        // phpType: currently supported are array and struct (php assoc array)
        'struct',
        // compositor (all|sequence|choice)
        'all',
        // restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
        '',
        // elements = array ( name = array(name=>'',type=>'') )
        array
        (
            'responseCode' => array(   'type' => 'xsd:int'),
            'responseMessage' => array(   'type' => 'xsd:string'),
            'stuffArray'   => array(   'type' => 'tns:StuffsArray'
                                            // DON'T UNCOMMENT THE FOLLOWING COMMENTED LINES, BECAUSE THIS WAY IT DOESN'T WORK!!! - Left it in the code not to forget it....
                                            // ,
                                            // 'minOccurs' => '0',
                                            // 'maxOccurs' => 'unbounded'
                                            )
        )
    );

    $server->register(
        // string $name the name of the PHP function, class.method or class..method
        'getStuffs',
        // array $in assoc array of input values: key = param name, value = param type
        array(
            'user' => 'xsd:string',
            'pass' => 'xsd:string'
        ),
        // array $out assoc array of output values: key = param name, value = param type
        array(
            'return' => 'tns:ResponseObject'
        ),
        // mixed $namespace the element namespace for the method or false
        // 'urn:' . $myNamespace,
        $myNamespace,
        // mixed $soapaction the soapaction for the method or false
        // 'urn:' . $myNamespace . "#getStuffs",
        $myNamespace . "#getStuffs",
        // mixed $style optional (rpc|document) or false Note: when 'document' is specified, parameter and return wrappers are created for you automatically
        'rpc',
        // mixed $use optional (encoded|literal) or false
        'encoded',
        // string $documentation optional Description to include in WSDL
        'Fetch array of Stuffs ("id", "name").' // documentation
    );

    // $server->wsdl->schemaTargetNamespace = $myNamespace;

    // function def.: nusoap/lib/class.soap_server.php 
    $server->service(isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '');

    exit(0);
 
ไม่รู้จะทันไหมนะครับ

กระทู้ทีเกี่ยวข้อง
https://www.mindphp.com/forums/viewtopic ... 29&t=12011
https://www.mindphp.com/forums/viewtopic.php?t=2324
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: Amazon [Bot] และบุคลทั่วไป 113