php自带SOAP扩展调用web service
提起php调用web service,在php4年代的人会立即想到用nusoap调用,这个nusoap是个好东东,不过年久未更新,恐其中会有众多漏洞了,正好已经进入了php5年代了,调用web service用自带的扩展岂不快哉!
前提:打开php5的web service扩展
环境需求:
This extension makes use of the GNOME xml library. Download and install this library. You will need at least libxml-2.5.4.
Linux下,
This extension is only available if PHP was configured with --enable-soap<br>
Windows下:<br>
php.ini文件中 <font face="Verdana">extension=php_soap.dll</font> 去掉注释即可<br>
<br>
其次:调用实践,以下是俺近期调用的算是一些总结吧<br>
<br>
<p><font face="Verdana">手册摘录:<br>
SoapClient->__soapCall()<br>
说明<br>
class SoapClient { </font></p>
<p><font face="Verdana">mixed __soapCall ( string function_name, array arguments [, array options [, mixed input_headers [, array &output_headers]]] )</font></p>
<p><font face="Verdana">}<br>
This is a low level API function that is used to make a SOAP call. Usually, in WSDL mode, you can simply call SOAP functions as SoapClient methods. This method useful in non-WSDL mode when soapaction is unknown, uri differs from the default or when sending and/or receiving SOAP Headers. </font></p>
<p><font face="Verdana">On error, a call to a SOAP function can cause PHP to throw exceptions or return a SoapFault object if exceptions are disabled. To check if the function call failed to catch the SoapFault exceptions, check the result with is_soap_fault(). </font></p>
<p><font face="Verdana">返回值<br>
SOAP functions may return one, or multiple values. If only one value is returned by the SOAP function, the return value of __soapCall will be a simple value (e.g. an integer, a string, etc). If multiple values are returned, __soapCall will return an associative array of named output parameters. </font></p>
<p><font face="Verdana">范例<br>
例 1. SoapClient->__soapCall() Examples</font></p>
<p><font face="Verdana"><?php </font></font></p>
<p><font face="Verdana">$client = new SoapClient("some.wsdl");<br>
$client->SomeFunction($a, $b, $c);</font></p>
<p><font face="Verdana">$client->__soapCall("SomeFunction", array($a, $b, $c));<br>
$client->__soapCall("SomeFunction", array($a, $b, $c), NULL,<br>
new SoapHeader(), $output_headers);</font></p>
<font face="Verdana">
<p><br>
$client = new SoapClient(null, array('location' => "http://localhost/soap.php",<br>
'uri' => "http://test-uri/"));<br>
$client->SomeFunction($a, $b, $c);<br>
$client->__soapCall("SomeFunction", array($a, $b, $c));<br>
$client->__soapCall("SomeFunction", array($a, $b, $c),<br>
array('soapaction' => 'some_action',<br>
'uri' => 'some_uri'));<br>
?> <br>
</p>
<p> </p>
<p>1.in WSDL mode,soapCall应用web service,例子用的是asp.net的web service,提供service.asmx页面,调用及查看都比较简单,手册上的example也大多是这个类型,比较简单</p>
<p>SOAP发送的协议:</p>
<p>POST /servicepath/service.asmx HTTP/1.1<br>
Host: 211.186.1.4<br>
Content-Type: text/xml; charset=utf-8<br>
Content-Length: length<br>
SOAPAction: "http://211.186.5.15/Service/ServiceMethod"</p>
<p><?xml version="1.0" encoding="utf-8"?><br>
<envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><br>
<body>
<br>
<servicemethod xmlns="http://211.186.5.15/Service"><br>
<param1>string</param1><br>
<param2>string</param2><br>
<param3>string</param3><br>
</servicemethod><br>
</body>
<br>
</envelope></p>
<p>调用方法:<br>
$client = new SoapClient("http://www.xxx.com/service/service.asmx?WSDL");<br>
//向SOAP服务方发送参数值<br>
$param1 = "p1";<br>
$param2 = "p2";<br>
$param3 = "p3";</p>
<p>//serviceParam1,serviceParam2,serviceParam3为发送参数值所对应的参数名(或service端提供的字段名)<br>
$param = array('serviceParam1' => $param1,'serviceParam2' => $param2,'serviceParam3' => $param3);</p>
<p>//方法名为ServiceMethod,参数数组为$param,默认以parameters字段标示传递的参数数组<br>
$arr = $client->__soapCall('ServiceMethod',array('parameters' => $param));<br>
print_r($arr);</p>
<p><br>
2.in non-WSDL mode,这种情况下soapaction is unknown</p>
<p>SOAP发送协议</p>
<p>POST /services/SoapMethod?WSDL HTTP/1.1<br>
Host: 220.211.1.12:8088<br>
Connection: Keep-Alive<br>
User-Agent: PHP-SOAP/5.2.5<br>
Content-Type: text/xml; charset=utf-8<br>
SOAPAction: "urn:SoapMethod#ServiceMethod"<br>
Content-Length: 1297</p>
<p><?xml version="1.0" encoding="UTF-8"?><br>
<envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:SoapMethod" 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:ns2="http://220.211.1.12" soap-env:encodingstyle="http://schemas.xmlsoap.org/soap/encoding/"><br>
<body>
<br>
<servicemethod><br>
<servicemethodsection xsi:type="ns2:ServiceObjectType"><br>
<param1 xsi:type="xsd:string">01019</param1><br>
<param2 xsi:type="xsd:long">10</param2><br>
<param3 xsi:type="xsd:long">0</param3><br>
<param4 xsi:type="xsd:long">11</param4><br>
</servicemethodsection><br>
</servicemethod><br>
</body>
<br>
</envelope></p>
<p>调用方法:<br>
2.1传递一个参数:<br>
try {<br>
$client = new SoapClient(null, <br>
array('location' => 'http://192.168.1.180:8088/services/SoapPage?WSDL','uri' => 'http://192.168.1.180:8088/services/')); <br>
$result = $client->__soapCall('ServiceMethod', array('fieldName' => "data")); //以数组形式传递params <br>
//$result = $client->__soapCall('ServiceMethod', array(new SoapParam("data", 'fieldName'))); //以构造服务端参数的形式构造参数传递给服务端 <br>
var_dump($result);<br>
} <br>
catch (Exception $e) <br>
{<br>
printf("Message = %s",$e->__toString());<br>
}<br>
<br>
附:手册解释<br>
class SoapParam { </p>
<p>__construct ( mixed data, string name )</p>
<p>}<br>
参数</p>
<p>data<br>
The data to pass or return. You can pass this parameter directly as PHP value, but in this case it will be named as paramN and the SOAP Service may not understand it. </p>
<p>name<br>
The parameter name</p>
<p>2.2传递多个参数:<br>
如果服务端在non wsdl的情况下要求传递一个对象参数,该对象中包含多个属性,则code如下</p>
<p>try {<br>
$client = new SoapClient(null, array('location' => 'http://192.168.1.180:8088/services/SoapPage?WSDL','uri' => 'urn:SoapName')); //uri部分也可能是uri地址</p>
<p> class Obj{ <br>
public $param1 = '01019';<br>
public $param2 = 10;<br>
public $param3 = 0;<br>
public $param4 = 11;<br>
}</p>
<p> $struct = new Obj(); //创建服务端要求传递的对象<br>
//如果服务端变态到传递的参数有的参数类型是你编程语言中没有的数据类型,如本人用php,没有Java的Long类型(一般做web service都要考虑到通用性,数据类型都是string或int型,而且我认为根本没必要用Long类型。没办法服务端不改,只能我这边改)就要将参数进行强制类型转换处理,这样的处理也只是在SOAP传输中将xml的参数类型替换成服务端所要求的类型名,并不是真实转化传递的数据类型<br>
$struct->param1 = iconv('gb2312','utf-8',$struct->param1);<br>
$struct->param2 = new SoapVar($struct->param2,XSD_LONG);<br>
$struct->param3 = new SoapVar($struct->param3,XSD_LONG);<br>
$struct->param4 = new SoapVar($struct->param4,XSD_LONG);</p>
<p> //序列化对象中使用SoapVar的方法参考php手册对SoapVar的解释,每个参数都解释的很清楚<br>
$soapstruct = new SoapVar($struct, SOAP_ENC_OBJECT, "ServiceObjectType", "http://soapinterop.org/xsd"); //对象序列化,注意区分,SOAP对象的序列化不是用serialize<br>
<br>
$result = $client-> ServiceMethod(new SoapParam($soapstruct, 'ServiceMethodSection')); <br>
//$result = $client->__soapCall('ServiceMethod', array(new SoapParam($soapstruct, 'ServiceMethodSection')));<br>
<br>
var_dump($result);<br>
} catch (Exception $e) {<br>
printf("Message = %s",$e->__toString());<br>
}</p>
<p>附:PEAR Manual中找到的SoapVar的解释<br>
SoapVar<br>
SoapVar -- Changes the Returntype of a variable<br>
Description</p>
<p>new SoapVar (mixed variable, long type)</p>
<p>Warning <br>
This function is EXPERIMENTAL. That means, that the behaviour of this function, the function name, in concreto ANYTHING documented here can change in a future release of this package WITHOUT NOTICE. Be warned, and use this function at your own risk.<br>
<br>
You can change the return type of variable - so that it works better with non-PHP applications for example. </p>
<p>type should be one of the following </p>
<p>XSD_1999_TIMEINSTANT <br>
XSD_STRING <br>
XSD_BOOLEAN <br>
XSD_DECIMAL <br>
XSD_FLOAT <br>
XSD_DOUBLE <br>
XSD_DURATION <br>
XSD_DATETIME <br>
XSD_TIME <br>
XSD_DATE <br>
XSD_GYEARMONTH <br>
XSD_GYEAR <br>
XSD_GMONTHDAY <br>
XSD_GDAY <br>
XSD_GMONTH <br>
XSD_HEXBINARY <br>
XSD_BASE64BINARY <br>
XSD_ANYURI <br>
XSD_QNAME <br>
XSD_NOTATION <br>
XSD_NORMALIZEDSTRING <br>
XSD_TOKEN <br>
XSD_LANGUAGE <br>
XSD_NMTOKEN <br>
XSD_NAME <br>
XSD_NCNAME <br>
XSD_ID <br>
XSD_IDREF <br>
XSD_IDREFS <br>
XSD_ENTITY <br>
XSD_ENTITYS <br>
XSD_INTEGER <br>
XSD_NONPOSITIVEINTEGER <br>
XSD_NEGATIVEINTEGER <br>
XSD_LONG <br>
XSD_INT <br>
XSD_SHORT <br>
XSD_BYTE <br>
XSD_NONNEGATIVEINTEGER <br>
XSD_UNSIGNEDLONG <br>
XSD_UNSIGNEDINT <br>
XSD_UNSIGNEDSHORT <br>
XSD_UNSIGNEDBYTE <br>
XSD_POSITIVEINTEGER <br>
</p></font><p>
<br>
HTTP协议精解.rar<br>
SOAP协议规范.rar<br>
</p>

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











PHP 8.4는 상당한 양의 기능 중단 및 제거를 통해 몇 가지 새로운 기능, 보안 개선 및 성능 개선을 제공합니다. 이 가이드에서는 Ubuntu, Debian 또는 해당 파생 제품에서 PHP 8.4를 설치하거나 PHP 8.4로 업그레이드하는 방법을 설명합니다.

VS Code라고도 알려진 Visual Studio Code는 모든 주요 운영 체제에서 사용할 수 있는 무료 소스 코드 편집기 또는 통합 개발 환경(IDE)입니다. 다양한 프로그래밍 언어에 대한 대규모 확장 모음을 통해 VS Code는

숙련된 PHP 개발자라면 이미 그런 일을 해왔다는 느낌을 받을 것입니다. 귀하는 상당한 수의 애플리케이션을 개발하고, 수백만 줄의 코드를 디버깅하고, 여러 스크립트를 수정하여 작업을 수행했습니다.

이 튜토리얼은 PHP를 사용하여 XML 문서를 효율적으로 처리하는 방법을 보여줍니다. XML (Extensible Markup Language)은 인간의 가독성과 기계 구문 분석을 위해 설계된 다목적 텍스트 기반 마크 업 언어입니다. 일반적으로 데이터 저장 AN에 사용됩니다

JWT는 주로 신분증 인증 및 정보 교환을 위해 당사자간에 정보를 안전하게 전송하는 데 사용되는 JSON을 기반으로 한 개방형 표준입니다. 1. JWT는 헤더, 페이로드 및 서명의 세 부분으로 구성됩니다. 2. JWT의 작업 원칙에는 세 가지 단계가 포함됩니다. JWT 생성, JWT 확인 및 Parsing Payload. 3. PHP에서 인증에 JWT를 사용하면 JWT를 생성하고 확인할 수 있으며 사용자 역할 및 권한 정보가 고급 사용에 포함될 수 있습니다. 4. 일반적인 오류에는 서명 검증 실패, 토큰 만료 및 대형 페이로드가 포함됩니다. 디버깅 기술에는 디버깅 도구 및 로깅 사용이 포함됩니다. 5. 성능 최적화 및 모범 사례에는 적절한 시그니처 알고리즘 사용, 타당성 기간 설정 합리적,

문자열은 문자, 숫자 및 기호를 포함하여 일련의 문자입니다. 이 튜토리얼은 다른 방법을 사용하여 PHP의 주어진 문자열의 모음 수를 계산하는 방법을 배웁니다. 영어의 모음은 A, E, I, O, U이며 대문자 또는 소문자 일 수 있습니다. 모음이란 무엇입니까? 모음은 특정 발음을 나타내는 알파벳 문자입니다. 대문자와 소문자를 포함하여 영어에는 5 개의 모음이 있습니다. a, e, i, o, u 예 1 입력 : String = "Tutorialspoint" 출력 : 6 설명하다 문자열의 "Tutorialspoint"의 모음은 u, o, i, a, o, i입니다. 총 6 개의 위안이 있습니다

정적 바인딩 (정적 : :)는 PHP에서 늦은 정적 바인딩 (LSB)을 구현하여 클래스를 정의하는 대신 정적 컨텍스트에서 호출 클래스를 참조 할 수 있습니다. 1) 구문 분석 프로세스는 런타임에 수행됩니다. 2) 상속 관계에서 통화 클래스를 찾아보십시오. 3) 성능 오버 헤드를 가져올 수 있습니다.

Python은 초보자에게 문제 해결 능력을 부여합니다. 사용자 친화적인 구문, 광범위한 라이브러리 및 변수, 조건문 및 루프 사용 효율적인 코드 개발과 같은 기능을 제공합니다. 데이터 관리에서 프로그램 흐름 제어 및 반복 작업 수행에 이르기까지 Python은 제공합니다.
