教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 PHP SOAP调用.net的WebService数据的实例代码

PHP SOAP调用.net的WebService数据的实例代码

发布时间:2017-04-16   编辑:jiaochengji.com
分享一例php代码,使用SOAP调用.net的WebService数据,学习php SOAP的用法,感兴趣的朋友不妨参考学习下。

本节内容:
SOAP调用.net的WebService数据

与.net系统进行数据交换,对方提供了一个WebService接口,在php中考虑使用SOAP调用对方的WebService数据。

与一般的PHP POST或GET传值再查库拿数据的思路不同,需要用到SOAP模块。
首先,确认PHP.ini开启了.SOAP,即extension=php_soap.dll 去掉前的分号。


例子:
 

复制代码 代码示例:
<?php
/**
* SOAP调用.net的WebService数据
* edit: www.jbxue.com
*/
$client = new SoapClient('http://www.aa.net/SearchService.asmx?WSDL');//这个SOAP地址要换成你自己的
$client->soap_defencoding = 'utf-8'; 
$client->decode_utf8 = false;  
$client->xml_encoding = 'utf-8';
$param = array('param1'=>'01', 'param2'=>'02');
//$param["param1"]="01";
//$param["param2"]="02";
//$result = $client->__soapCall("GetArticle", array( $param ));
$result = $client->__Call("GetArticle", array( $param ));
if (is_soap_fault($result))
{
    trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
}
else
{
    $data = $result->GetArticleResult; //这里返回的是类,必须使用->得到元素的值
    print_r($data);
}
?>

注意:参数是数组外再包一层数组,就是 array( array() )

附,SOAP接口的一些参数:
以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。
 

复制代码 代码示例:
POST /SearchService.asmx HTTP/1.1
Host: 202.105.183.61
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/GetTrafficViolationInfo"
<?xml version="1.0" encoding="utf-8"?>
<soap: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/">
  <soap:Body>
    <GetArticle xmlns="http://tempuri.org/">
      <param1>string</param1>
      <param2>string</param2>
    </GetArticle>
  </soap:Body>
</soap:Envelope>

您可能感兴趣的文章:
PHP SOAP调用.net的WebService数据的实例代码
php调用WebService传递时间参数的方法
基于JQuery的访问WebService的代码(可访问Java[Xfire])
asp.net WebService jquery访问实例
php soap 调用webservice应用测试
php捕捉soap的xml形式
C#做的一个加密/解密的类
c# WebService实例分享
php soap客户端调试实例
.NET 世界中的远程脚本 (转)

[关闭]
~ ~