2014-07-25 8 views
0

내 코드가 잘못 되었나요? 내 Math 클래스 용 SOAP 서비스를 만드는 방법은 무엇입니까?
Math.php에 대한 네임 스페이스에 대해서는 언급하지 않았습니다. 브라우저에서 메시지가 class Math does not exist 이니까요. Math 클래스의 네임 스페이스를 언급하지 않고 indexAction()에서 Math 객체를 만드는 방법.
Math 클래스에 대한 첫 wsdl을 작성하는 방법을 알려주십시오.ZF2를 사용하여 SOAP 서비스를 만드는 방법은 무엇입니까?

폴더 구조
모듈
--Soap
---- 컨트롤러
------> IndexController.php
---- ------ 서비스
> Math.php

IndexController.php

include_once __DIR__ . '/../Services/Math.php' 
class IndexController extends AbstractActionController 
{ 
    private $_URI = "http://zf2.services/soap"; 
    public function indexAction() 
    { 
    $server = new Server(null, array('uri' => $this->_URI)); 
    $server->setClass('Math'); 
    //$server->setObject(new Math()); 
    $server->handle(); 
    } 
} 
,

Math.php

//namespace Soap\Services; 
    class Math 
    { 
     /** 
     * Method 
     * @return string 
     */ 
     public function greeting() 
     { 
     return 'Hello world'; 
     } 
    } 

는 XML

<SOAP-ENV ..> 
<SOAP-ENV:Body> 
    <SOAP-ENV:Fault> 
    <faultcode>sender</faultcode> 
    <faultstring>Invalid XML</faultstring> 
    </SOAP-ENV:Fault> 
</SOAP-ENV:Body> 
</SOAP-ENV> 

답변

0

당신은 Math.php에 기록 된 네임 스페이스에 대해 옳다을 결과.

include_once __DIR__ . '/../Services/Math.php'; 

class IndexController extends AbstractActionController { 

    private $_URI = "http://zf2.services/soap"; 

    public function indexAction() { 
     $autodiscover = new \Zend\Soap\AutoDiscover(); 
     $autodiscover->setClass('Math') 
        ->setBindingStyle(array('style' => 'document')) 
        ->setUri($this->_URI); 
     header('Content-type: application/xml'); 
     echo $autodiscover->toXml(); 
     exit(); 
    } 
} 

나는 그것을 시도하고 그것을 잘 작동합니다 -

는 IndexController.php이보십시오.

+0

이전 접근 방식의 문제점은 무엇입니까? 어떻게 soapclient에서이 wsdl을 소비 할 수 있습니까? –

+0

ZF2 SOAP에 대한 몇 가지 참조 링크를 제공 할 수 있습니까? –

+0

이 링크로 충분합니다. http://framework.zend.com/manual/2.3/en/modules/zend.soap.auto-discovery.html 세부 구현을 위해 특별히 작성된 Google 블로그를 만들어야합니다. 적어도 그것이 내가 ZF2를 배운 방법입니다. 행운을 빕니다. –

관련 문제