Home > Backend Development > PHP Tutorial > PHP uses SOAP to call .net WebService problem_PHP tutorial

PHP uses SOAP to call .net WebService problem_PHP tutorial

WBOY
Release: 2016-07-13 10:34:10
Original
721 people have browsed it

The project needs to exchange data with a .net system, and the partner provides a WebService interface. This is a bit different from the general PHP POST or GET method of passing values ​​and then checking the database to get the data. You need to use the SOAP module. The processing method is also very simple, but there are some things that need to be paid attention to.

First make sure that .SOAP is enabled in your PHP.ini, that is, remove the semicolon in front of extension=php_soap.dll.

The code is very simple:

<?php

$client = new SoapClient('http://www.bkjia.com/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);
}
?>
Copy after login

One thing to note is that the parameter is an array wrapped in an array, which is array( array() )

Attached are some parameters of the SOAP interface:

The following is a sample SOAP 1.2 request and response. Placeholders shown need to be replaced with actual values.

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>
Copy after login
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>
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/752322.htmlTechArticleThe project needs to exchange data with a .net system, and the partner provides a WebService interface. This is a bit different from the general PHP POST or GET method of passing values ​​and then checking the library to get the data...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template