2013-06-25 2 views
0

저는 webservice를 처음 사용하면서 웹 서비스를 만드는 방법을 살펴 보았습니다. 지금은 어떻게 든 만들 수 있다고 생각하지만 어떤 결과도 반환하지 않습니다. nusoap과 Codeigniter를 사용하고 있습니다.nusoap codeigniter webservice 서버 및 클라이언트

WebService에 서버가 아래 WebServiceTester

라는 응용 프로그램에서 서버로 서비스를 제공하는 Bills_WS 컨트롤러에 대한 코드입니다 :

class Bills_WS extends CI_Controller 
{ 
    function __construct() 
    { 
     parent:: __construct();   
    } 

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

     $namespace = "http://localhost:8080/webservicetester/bills_ws.php?wsdl"; 

     $server = new nusoap_server; 
     $server->configureWSDL('WebServiceTester'); 
     $server->wsdl->schemaTargetNamespace = $namespace; 

     $server->register('hello'); 

     $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; 
     $server->service($HTTP_RAW_POST_DATA); 
    } 
    function hello() 
    { 
     return "greetings from server"; 
    } 
} 

하고 전화, 나는 다른 응용 프로그램에서 호출 오전 (동일한 시스템)은 ws_client 라이브러리에서 ussccsv1을 호출하여 트랜잭션 컨트롤러에 사용됩니다.

class Ws_client 
{ 
    private $CI = null; 
    function __construct() 
    { 
     $this->CI =& get_instance(); 
    } 

    public function transaction_send_ws($param) 
    { 
     $this->CI->load->library('nuSoap_lib'); 

     $url = 'http://localhost/webservicetester.php/bills_ws?wsdl'; 

     $client = new nusoap_client($url); 
     $response = $client->call('hello'); 

     if($client->fault) 
     { 
      echo "FAULT:".$client->faultcode; 
      echo "string: ".$client->faultstring; 
     } 
     else 
     { 
      $r = $response; 
      count($r); 
echo "count".count($r); 

     } 
    } 
} 

class Nusoap_lib 
{ 
    function nusoap_lib() 
    { 
     include(APPPATH.'libraries/nusoap/nusoap'.EXT); 
    } 
} 

제 질문은 다음과 같습니다 : 1. 어떻게 bills_ws에서 웹 서비스를 호출 할 내가 사용하고 있으므로 nusoap_lib을 포함? $url이 맞습니까? 지금까지는 404 오류 HTTP를 찾을 수 없습니다. 2. 오류가 ws_client 또는 bills_ws입니까? 3. 내가 에코를 울리면 ws_client = 1count($r)이 표시됩니다.

이 튜토리얼을 따라하려고 노력하지만, 나는 완전히 이해하지 않는 것 : - http://www.phpeveryday.com/articles/PHP-Web-Services-Fetching-Data-From-Database-P105.html - http://ellislab.com/forums/viewthread/59710/

미리 감사드립니다.

+1

문제를 해결 : 문제를 해결 한 경우 이 http://board.phpbuilder.com/showthread.php?10224396-php-xml-NuSoap-!working – Ponce

+0

, 게시하시기 바랍니다 : 그것을 해결하기 위해이 예제를 사용 여기서 답을하고 대답을 받아들이면 다른 사람도 유익합니다. – Sushil

답변

2

위 코드를위한 해결책.

컨트롤러 :

<?php 
class Bills_WS extends CI_controller { 
    function __construct() { 
     parent::__construct(); 

     $this->load->library("Nusoap_lib"); 
     $this->load->model("Member"); 

     $this->nusoap_server = new soap_server(); 
     $this->nusoap_server->configureWSDL("Bills_WSDL", "urn:Bills_WSDL"); 

     $this->nusoap_server->register('hello',    // method name 
      array('name' => 'xsd:string'),  // input parameters 
      array('return' => 'xsd:string'),  // output parameters 
      'urn:Bills_WSDL',      // namespace 
      'urn:Bills_WSDL#hello',    // soapaction 
      'rpc',        // style 
      'encoded',       // use 
      'Says hello to the caller'   // documentation 
     ); 
    } 

    function index(){ 

     if($this->uri->rsegment(3) == "wsdl") { 
      $_SERVER['QUERY_STRING'] = "wsdl"; 
     } else { 
      $_SERVER['QUERY_STRING'] = ""; 
     }   

     function hello($name) { 
       return 'Hello, ' . $name; 
     } 
     $this->nusoap_server->service(file_get_contents("php://input")); 
    } 

} 

확인 항목 액세스 WSDL

$route['Bills_WS/wsdl'] = "Bills_WS/index/wsdl"; 

/config/routes.php에서

http://localhost/ci_nusoap/index.php/Bills_WS/wsdl 

난 당신이 브라우저에서 XML을 볼 수 있기를 바랍니다이 URL에 의해 지금.

SOAP 클라이언트 코드.

<?php 
class Soap_client extends CI_controller { 

    function __construct() { 
     parent::__construct(); 

     $this->load->library("Nusoap_lib"); 
     $this->load->helper("url"); 

    } 

    function index() { 

     $this->soapclient = new soapclient(site_url('Bills_WS/index/wsdl'), true); 

     $err = $this->soapclient->getError(); 
     if ($err) { 
      echo '<h2>Constructor error</h2><pre>' . $err . '</pre>'; 

     } 

     $result = $this->soapclient->call('hello', array('name' => 'Scott')); 
     // Check for a fault 
     if ($this->soapclient->fault) { 
      echo '<h2>Fault</h2><pre>'; 
      print_r($result); 
      echo '</pre>'; 
     } else { 
      // Check for errors 
      $err = $this->soapclient->getError(); 
      if ($err) { 
       // Display the error 
       echo '<h2>Error</h2><pre>' . $err . '</pre>'; 
      } else { 
       // Display the result 
       echo '<h2>Result</h2><pre>'; 
       print_r($result); 
      echo '</pre>'; 
      } 
     } 
    } 



} 

액세스 SOAP 클라이언트 이제

http://localhost/ci_nusoap/index.php/soap_client 

완료.

+0

나는 별도의 클래스 라이브러리를 만들었고 거기에서 Master.fruits와 같은 클래스를 사용하여 메서드를 호출한다. Master => class와 fruits => Method, PHP에서는 잘 작동하지만 C#에서는 오류가 발생하지 않아야한다. 그것은 masterfruits, 모든 아이디어가 있어야합니다. – musthafa

+0

나에게 C# 코드 스 니펫을 제공 할 수 있습니까? –