前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >PHP使用SOAP调用.net的WebService问题

PHP使用SOAP调用.net的WebService问题

作者头像
wangxl
发布2018-03-07 15:58:59
1.6K0
发布2018-03-07 15:58:59
举报
文章被收录于专栏:PHP在线PHP在线

项目的需求,需要和一个.net系统进行数据交换,合作方提供了一个WebService接口。这个与一般的PHP POST或GET传值再查库拿数据的思路有点不一样,需要用到SOAP模块,处理方法也很简单,就是有一些需要注意的事情。

首先确认你的PHP.ini开启了.SOAP,就是 extension=php_soap.dll 这前面的分号去咯。

代码很简单:

代码语言:javascript
复制
<?php

$client = new SoapClient('http://www.nowamagic.net/SearchService.asmx?WSDL');

$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 请求和响应示例。所显示的占位符需替换为实际值。

代码语言:javascript
复制
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>
代码语言:javascript
复制
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?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>
    <GetArticleResponse xmlns="http://tempuri.org/">
      <GetArticleResult>string</GetArticleResult>
    </GetArticleResponse>
  </soap:Body>
</soap:Envelope>
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2015-07-29,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 php 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档