天天看点

PHP Webservice知识点笔记最近有项目用到webservice,简单、简单、简单(重要的事情说3遍)的把相关知识点进行整理,用于备忘。1     XML相关2     SOAP 相关

最近有项目用到webservice,简单、简单、简单(重要的事情说3遍)的把相关知识点进行整理,用于备忘。

1     XML相关

1.1   XML命名空间

XML 命名空间属性被放置于元素的开始标签之中,并使用以下的语法:

xmlns:namespace-prefix="namespaceURI"      

为元素定义默认的命名空间可以让我们省去在所有的子元素中使用前缀的工作。如下:

xmlns="namespaceURI"

1.2   XML schema

XML Schema 是基于 XML 的 DTD 替代者。

XML Schema 可描述 XML 文档的结构。

XML Schema 语言也可作为 XSD(XML Schema Definition)来引用

1.2.1 基本结构

<?xml version="1.0"?>

<xs:schemaxmlns:xs="http://www.w3.org/2001/XMLSchema"

targetNamespace="http://www.w3school.com.cn"

xmlns="http://www.w3school.com.cn"

elementFormDefault="qualified">

...

...

</xs:schema>

2     SOAP 相关

2.1   WSDL

         WSDL是一种使用 XML 编写的文档。这种文档可描述某个 Web service。它可规定服务的位置,以及此服务提供的操作(或方法)。

2.1.1 基本结构

<definitions>

<types>

   definition of types........

</types>

<message>

   definition of a message....

</message>

<portType>

   definition of a port.......

</portType>

<binding>

   definition of a binding....

</binding>

</definitions>

2.2   SOAP

         SOAP是基于 XML 的简易协议,可使应用程序在 HTTP 之上进行信息交换。

或者更简单地说:SOAP 是用于访问网络服务的协议。

2.2.1 构建模块

·       必需的 Envelope 元素,可把此 XML 文档标识为一条 SOAP 消息

·       可选的 Header 元素,包含头部信息

·       必需的 Body 元素,包含所有的调用和响应信息

·       可选的 Fault 元素,提供有关在处理此消息所发生错误的信息

2.2.2 语法规则

·       SOAP 消息必须用 XML 来编码

·       SOAP 消息必须使用 SOAP Envelope 命名空间

·       SOAP 消息必须使用 SOAP Encoding 命名空间

·       SOAP 消息不能包含 DTD 引用

·       SOAP 消息不能包含 XML 处理指令

2.2.3 基本结构

<?xml version="1.0"?>

<soap:Envelope

xmlns:soap="http://www.w3.org/2001/12/soap-envelope"

soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Header>

  ...

  ...

</soap:Header>

<soap:Body>

  ...

  ...

 <soap:Fault>

    ...

    ...

 </soap:Fault>

</soap:Body>

</soap:Envelope>

2.3   PHP SoapServer类

2.3.1  SoapServer 

         public SoapServer::SoapServer ( mixed 

$wsdl

 [, array 

$options

 ] )

         可以创建wsdl模式和非wsdl模式的soapServer对象

SoapServer {

    public void addFunction ( mixed $functions )

    public void addSoapHeader ( SoapHeader $object )

    public __construct ( mixed $wsdl [, array $options ] )

    public void fault ( string $code , string $string [, string $actor [, string $details [, string $name ]]] )

    public array getFunctions ( void )

    public void handle ([ string $soap_request ] )

    public void setClass ( string $class_name [, mixed $args [, mixed $... ]] )

    public void setObject ( object $object )

    public void setPersistence ( int $mode )

    public SoapServer ( mixed $wsdl [, array $options ] )

}

2.4   PHP SoapClient类

SoapClient {

    public mixed __call ( string $function_name , string $arguments )

    public SoapClient ( mixed $wsdl [, array $options ] )

    public string __doRequest ( string $request , string $location , string $action , int $version [, int $one_way = 0 ] )

    public array __getFunctions ( void )

    public string __getLastRequest ( void )

    public string __getLastRequestHeaders ( void )

    public string __getLastResponse ( void )

    public string __getLastResponseHeaders ( void )

    public array __getTypes ( void )

    public void __setCookie ( string $name [, string $value ] )

    public string __setLocation ([ string $new_location ] )

    public bool __setSoapHeaders ([ mixed $soapheaders ] )

    public mixed __soapCall ( string $function_name , array $arguments [, array $options [, mixed $input_headers

 [,array &$output_headers ]]] )

    public SoapClient ( mixed $wsdl [, array $options ] )

}

2.5   PHP SoapHeader

SoapHeader::SoapHeader ( string 

$namespace

 , string 

$name

 [, mixed 

$data

 [, bool 

$mustunderstand

 = false [, string

$actor

 ]]] )

2.6   PHP SoapParam

SoapParam::SoapParam ( mixed $data , string $name )

2.7   PHP SoapFault

SoapFault::SoapFault ( string 

$faultcode

 , string 

$faultstring

 [, string 

$faultactor

 [, string 

$detail

 [, string

$faultname

 [, string 

$headerfault

 ]]]] )

下一篇《PHP Webservice简单实例》是一个简单的实例:

http://blog.csdn.net/dglxsong/article/details/52729880