SOAP:过程“ helloRequest”不存在

时间:2018-12-19 10:32:19

标签: php soap

我正在使用此文档在Symfony中创建SOAP服务:https://symfony.com/doc/2.8/controller/soap_web_service.html

我已经在PHPUnit中创建了一个测试:

class SOAPServiceControllerTest extends \PHPUnit\Framework\TestCase
{

    /** @test */
    public function it_should_process_a_hello_soap_request()
    {
        // Setup SoapClient
        $client = new \SoapClient(
            'https://example.com/soap/1.0/SOAPService?wsdl',
            [
                'stream_context' => stream_context_create(
                    [
                        'ssl' => [
                            'verify_peer' => false,
                            'verify_peer_name' => false,
                            'allow_self_signed' => true,
                        ],
                    ]
                ),
                'cache_wsdl' => WSDL_CACHE_NONE,
                'trace' => 1,
                'exception' => true,
                'login' => 'username',
                'password' => 'password',
            ]
        );

        // Call method on SoapClient
        $result = $client->hello('name');

        // Assert
        self::assertEquals('Hello, name', $result);
    }
}

然后我从Symfony文档中获取了代码:

控制器

class SOAPServiceController extends Controller
{

    /**
     * @Route("/1.0/SOAPService")
     */
    public function index()
    {
        // Render wsdl with Twig
        /** @var \Twig\Environment $twig */
        $twig = $this->container->get('twig');
        $wsdlContent = $twig->render('AppBundle:Soap:hello.xml.twig', ['domain' => 'example.com']);

        // Convert wsdl content to data uri because SoapServer can not consume wsdl content as a normal string
        $wsdlDataUri = 'data://text/plain;base64,'.base64_encode($wsdlContent);

        // Instantiate SoapServer with wsdl
        $soapServer = new \SoapServer($wsdlDataUri, ['cache_wsdl' => WSDL_CACHE_NONE]);

        // Set service to handle SOAP request
        $helloService = $this->container->get('hello.service');
        $soapServer->setObject($helloService);

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

        // Capture output and put it into the response object
        ob_start();
        $soapServer->handle();
        $response->setContent(ob_get_clean());

        return $response;
    }
}

服务

class HelloService
{

    public function hello(string $name): string
    {
        return 'Hello, ' . $name;
    }
}

我正在使用此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="https://example.com/soap/1.0/SOAPService?wsdl" />
      </port>
   </service>
</definitions>

PHPUnit中的测试有效,但是当我以XML格式发布SOAP请求时,会引发错误:'SOAP-ENV:ServerProcedure'helloRequest'不存在'

我使用了此SOAP请求:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <helloRequest>
      <hello>
        <name>test</name>
      </hello>
    </helloRequest>
  </soap:Body>
</soap:Envelope>

1 个答案:

答案 0 :(得分:0)

我能够使用PHPUnit测试中的SOAP Request输出解决此问题。

adb shell am start --activity-brought-to-front -n com.google.android.dialer/com.android.incallui.InCallActivity 表明Security exception: Permission Denial: starting Intent { flg=0x10400000 cmp=com. google.android.dialer/com.android.incallui.InCallActivity } from null (pid=12862 , uid=2000) not exported from uid 10102 java.lang.SecurityException: Permission Denial: starting Intent { flg=0x10400000 cmp=com.google.android.dialer/com.android.incallui.InCallActivity } from null ( pid=12862, uid=2000) not exported from uid 10102 at com.android.server.am.ActivityStackSupervisor.checkStartAnyActivityPe 节点不应在请求中。