SOAP簡單例子

來源:互聯網
上載者:User

簡介:這是SOAP簡單例子的詳細頁面,介紹了和php,有關的知識、技巧、經驗,和一些php源碼等。

class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=339598' scrolling='no'>

soap_client.php

<?php  $client = new SoapClient('http://www.phptest.com/soap/soap_server.php?WSDL');  //$client = new SoapClient('http://localhost/php/soap/math.wsdl');  try {    $result = $client->div(10, 2); // will cause a Soap Fault if divide by zero    print "The answer is: $result";  } catch(SoapFault $e) {    print "Sorry an error was caught executing your request: {$e->getMessage()}";  }?>

soap_server.php

<?phpclass math {  public function add($a, $b) {    return $a + $b;  }    public function div($a, $b) {    if($b == 0) {      throw new SoapFault(-1, "Cannot divide by zero!");    }    return $a / $b;  }  }$server = new SoapServer('math.wsdl', array('soap_version' => SOAP_1_2));$server->setClass("math");$server->handle();  ?>

math.wsdl (可以通過zend studio產生)

<?xml version='1.0' encoding='UTF-8'?><!-- WSDL file generated by Zend Studio. --><definitions name="math" targetNamespace="urn:math" xmlns:typens="urn:math" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/"><message name="add"><part name="a" type="xsd:integer"/><part name="b" type="xsd:integer"/></message><message name="addResponse"><part name="addReturn" type="xsd:integer"/></message><message name="div"><part name="a" type="xsd:integer"/><part name="b" type="xsd:integer"/></message><message name="divResponse"><part name="divReturn" type="xsd:double"/></message><portType name="mathPortType"><documentation>A simple math utility class</documentation><operation name="add"><documentation>Add two integers together</documentation><input message="typens:add"/><output message="typens:addResponse"/></operation><operation name="div"><documentation>Div two integers from each other</documentation><input message="typens:div"/><output message="typens:divResponse"/></operation></portType><binding name="mathBinding" type="typens:mathPortType"><soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/><operation name="add"><soap:operation soapAction="urn:mathAction"/><input><soap:body namespace="urn:math" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:body namespace="urn:math" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation><operation name="div"><soap:operation soapAction="urn:mathAction"/><input><soap:body namespace="urn:math" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:body namespace="urn:math" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation></binding><service name="mathService"><port name="mathPort" binding="typens:mathBinding"><soap:address location="http://www.phptest.com/soap/soap_server.php"/></port></service></definitions>

愛J2EE關注Java邁克爾傑克遜視頻站JSON線上工具

http://biancheng.dnbcw.info/php/339598.html pageNo:7

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.