2014-11-24 145 views
1

我用这个tutorial中的symfony2编写了一个web服务。与symfony的soap web服务

我的溃败是:

_soap: 
path:  /soap 
defaults: { _controller: AcmeSoapBundle:Default:index} 

我的配置:

services: 
hello_service: 
    class: Acme\SoapBundle\Services\HelloService 
    arguments: ["@mailer"] 

我的服务:

namespace Acme\SoapBundle\Services; 

class HelloService 
{ 
    private $mailer; 

    public function __construct(\Swift_Mailer $mailer) 
    { 
     $this->mailer = $mailer; 
    } 

    public function hello($name) 
    { 

     $message = \Swift_Message::newInstance() 
      ->setTo('[email protected]') 
      ->setSubject('Hello Service') 
      ->setBody($name . ' says hi!'); 

     $this->mailer->send($message); 

     return 'Hello, '.$name; 
    } 
} 

我的控制器:

namespace Acme\SoapBundle\Controller; 

use Symfony\Bundle\FrameworkBundle\Controller\Controller; 
use Symfony\Component\HttpFoundation\Response; 

class DefaultController extends Controller 
{ 
    public function indexAction() 
    { 
     $server = new \SoapServer('hello.wsdl'); 
     $server->setObject($this->get('hello_service')); 

     $response = new Response(); 
     $response->headers->set('Content-Type', 'text/xml; charset=ISO-8859-1'); 

     ob_start(); 
     $server->handle(); 
     $response->setContent(ob_get_clean()); 

     return $response; 
    } 
} 

hello.wsdl(网络/ hello.wsdl)

<?xml version="1.0" encoding="ISO-8859-1"?> 
<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="urn:arnleadservicewsdl" 
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
    xmlns="http://schemas.xmlsoap.org/wsdl/" 
    targetNamespace="urn:helloservicewsdl"> 

    <types> 
     <xsd:schema targetNamespace="urn:hellowsdl"> 
      <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" /> 
      <xsd:import namespace="http://schemas.xmlsoap.org/wsdl/" /> 
     </xsd:schema> 
    </types> 

    <message name="helloRequest"> 
     <part name="name" type="xsd:string" /> 
    </message> 

    <message name="helloResponse"> 
     <part name="return" type="xsd:string" /> 
    </message> 

    <portType name="hellowsdlPortType"> 
     <operation name="hello"> 
      <documentation>Hello World</documentation> 
      <input message="tns:helloRequest"/> 
      <output message="tns:helloResponse"/> 
     </operation> 
    </portType> 

    <binding name="hellowsdlBinding" type="tns:hellowsdlPortType"> 
     <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> 
     <operation name="hello"> 
      <soap:operation soapAction="urn:arnleadservicewsdl#hello" style="rpc"/> 

      <input> 
       <soap:body use="encoded" namespace="urn:hellowsdl" 
        encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> 
      </input> 

      <output> 
       <soap:body use="encoded" namespace="urn:hellowsdl" 
        encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> 
      </output> 
     </operation> 
    </binding> 

    <service name="hellowsdl"> 
     <port name="hellowsdlPort" binding="tns:hellowsdlBinding"> 
      <soap:address location="http://example.com/app.php/soap" /> 
     </port> 
    </service> 
</definitions> 

但我看到波纹管错误:

XML Parsing Error: no element found 
Location: http://xxx.xxxx.xxx/unproject/web/app_dev.php/soap 
Line Number 1, Column 1: 

我怎样才能解决这个问题呢? 感谢您的帮助

回答

0

我想你已经复制从该链接的WSDL文件的内容,但错过了改变location部分,你应该改变<soap:address location="http://example.com/app.php/soap" />到您自己的网址,例如,http://xxx.xxxx.xxx/unproject/web/app_dev.php/soap ..

+0

感谢您的回复,但它无法正常工作。 hamid 2014-11-25 06:34:42

+0

@hamid所以,改变它然后.. – xurshid29 2014-11-25 11:09:42

+0

@ xurchid29:正如我所说,我改变它但它不能正常工作!我怎么解决这个问题 ? – hamid 2014-11-25 11:33:29

0

编辑这一行你WSDL到的URL在你所暴露SoapServer的soap:address location="http://example.com/app.php/soap"

同时更换:
targetNamespace="urn:helloservicewsdl
到的
targetNamespace="urn:arnleadservicewsdl"

也看到,在您的的php.ini
soap.wsdl_cache_enabled=0 & & soap.wsdl_cache_ttl=0

使这一变化为我工作。