codebach / soap
构建和消费基于SOAP和WSDL的Web服务
Requires
- php: >=5.3.0
- ext-curl: *
- ext-soap: *
- ass/xmlsecurity: ~1.0
- symfony/framework-bundle: ~2.6
- symfony/twig-bundle: ~2.6
- zendframework/zend-mime: 2.1.*
Requires (Dev)
- ext-mcrypt: *
- mikey179/vfsstream: ~1.0
- symfony/filesystem: ~2.3
- symfony/process: ~2.3
Replaces
- codebach/soap-bundle: v1.0
- codebach/soap-client: v1.0
- codebach/soap-common: v1.0
- codebach/soap-server: v1.0
- codebach/soap-wsdl: v1.0
This package is not auto-updated.
Last update: 2024-09-20 21:06:41 UTC
README
这里是SOAP爱好者,BesimpleSoap扩展了很多新功能。
新功能(配置)
SoapClient
- 本地加载wsdl并使用不同的url进行请求(而不是本地wsdl文件)
- 基本Http认证支持
SoapServer
- 文档包装支持
- 可配置的wsdl定义名称属性
- 通过签名响应的Ws安全性
- 多个命名空间支持
安装
告诉Composer安装
composer require codebach/soap
用法
示例完整配置
be_simple_soap: clients: # Wsdl file and request url same place (Basic Usage) FooService: wsdl: wsdl_service_url # Wsdl file and request url different place BarService: wsdl: wsdl_file_to_load request_url: url_to_make_soap_requests basic_http_auth: login: login password: password services: # Single Namespace (Basic Usage) FooServer: namespace: namespace binding: document-wrapped # Or rpc-literal version: 2 resource: "@FooBundle/Controller/FooController.php" resource_type: annotation cache_type: none # Multiple Namespace BarServer: namespace: namespace binding: document-wrapped # Or rpc-literal version: 2 resource: '@BarBundle/Controller/BarController.php' resource_type: annotation cache_type: none target_name: ns1 # Service definition name attribute public_key: public_key_to_sign_response private_key: private_key_to_sign_response namespace_types: - { name: 'ns2', url: name_space2_url} - { name: 'ns3', url: name_space3_url}
多个命名空间使用
要将ComplexType放在不同的位置(例如:在上述yaml文件中配置),请使用新的Annotation类BeSimple\SoapBundle\ServiceDefinition\Annotation\Type
和新的参数target
,该参数属于BeSimple\SoapBundle\ServiceDefinition\Annotation\ComplexType
类
进行服务器配置
be_simple_soap: services: FooServer: namespace: default_namespace binding: document-wrapped version: 2 resource: '@FooBundle/Controller/DefaultController.php' resource_type: annotation cache_type: none target_name: ns1 namespace_types: - { name: 'ns2', url: 'foo_namespace'} - { name: 'ns3', url: 'bar_namespace'}
添加方法
use FooBundle\Server\SoapRequest; use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class DefaultController extends Controller { /** * @Soap\Method("soapRequest") * @Soap\Param("request", phpType = "FooBundle\Server\SoapRequest") * @Soap\Result("soapResponse", phpType = "FooBundle\Server\SoapResponse") */ public function soapRequestAction(SoapRequest $request) { } }
Bar.php
use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap; /** * @Soap\Alias("Bar") * @Soap\Type("ns3") */ class Bar { /** * @var string * * @Soap\ComplexType("string") */ private $value; /** * @return string */ public function getValue(): string { return $this->value; } /** * @param string $value */ public function setValue(string $value) { $this->value = $value; } }
Foo.php
use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap; /** * @Soap\Alias("Foo") * @Soap\Type("ns2") */ class Foo { /** * @var Bar * * @Soap\ComplexType("FooBundle\Server\Bar", target="ns3") */ private $bar; /** * @return Bar */ public function getBar(): Bar { return $this->bar; } /** * @param Bar $bar */ public function setBar(Bar $bar) { $this->bar = $bar; } }
SoapRequest.php
use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap; /** * @Soap\Alias("SoapRequest") * * Default namespace is ns1 */ class SoapRequest { /** * @var Foo * * @Soap\ComplexType("FooBundle\Server\Foo", target="ns2") */ private $foo; /** * @return Foo */ public function getFoo(): Foo { return $this->foo; } /** * @param Foo $foo */ public function setFoo(Foo $foo) { $this->foo = $foo; } }
以下是我们的服务器输出的xml
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="default_namespace" xmlns:ns="default_namespace/types" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="foo_namespace" xmlns:ns3="bar_namespace" name="ns1" targetNamespace="default_namespace"> <types> <xsd:schema xmlns:ns2="foo_namespace" xmlns:ns3="bar_namespace" targetNamespace="default_namespace" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xsd:complexType name="SoapRequest"> <xsd:sequence> <xsd:element name="foo" type="ns2:Foo"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="AppBundle.Server.SoapResponse"> <xsd:sequence/> </xsd:complexType> <xsd:element name="soapRequest" type="tns:soapRequest"/> <xsd:element name="soapRequestResponse" type="tns:soapRequestResponse"/> </xsd:schema> <xsd:schema xmlns:ns2="foo_namespace" targetNamespace="foo_namespace" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xsd:complexType name="Foo"> <xsd:sequence> <xsd:element name="bar" type="ns3:Bar"/> </xsd:sequence> </xsd:complexType> </xsd:schema> <xsd:schema xmlns:ns3="bar_namespace" targetNamespace="bar_namespace" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xsd:complexType name="Bar"> <xsd:sequence> <xsd:element name="value" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:schema> </types> <portType name="ns1PortType"> <operation name="soapRequest"> <input message="tns:soapRequest"/> <output message="tns:soapRequestResponse"/> </operation> </portType> <message name="soapRequest"> <part name="parameters" element="tns:soapRequest"/> </message> <message name="soapRequestResponse"> <part name="parameters" element="tns:soapRequestResponse"/> </message> <service name="ns1"> <port name="ns1Port" binding="tns:ns1Binding"> <soap:address location="https:///Symfony/Symfony28/web/app_dev.php/ws/v1/FooServer"/> </port> </service> <binding name="ns1Binding" type="tns:ns1PortType"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/> <operation name="soapRequest"> <soap:operation soapAction="default_namespace/soapRequest"/> <input> <soap:body use="literal" namespace="default_namespace" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </input> <output> <soap:body use="literal" namespace="default_namespace" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </output> </operation> </binding> </definitions>
组件
BeSimpleSoap由五个组件组成...
BeSimpleSoapBundle
BeSimpleSoapBundle是一个用于构建基于WSDL和SOAP的Web服务的Symfony2包。有关更多信息,请参阅README。
BeSimpleSoapClient
BeSimpleSoapClient是一个扩展了原生PHP SoapClient的组件,具有SwA、MTOM和WS-Security等更多功能。有关更多信息,请参阅README。
BeSimpleSoapCommon
BeSimpleSoapCommon组件包含服务器和客户端实现共享的功能。有关更多信息,请参阅README。
BeSimpleSoapServer
BeSimpleSoapServer是一个扩展了原生PHP SoapServer的组件,具有SwA、MTOM和WS-Security等更多功能。有关更多信息,请参阅README。
BeSimpleSoapWsdl
有关更多信息,请参阅README。