Я пробовал сервер SOAP PHP с клиентом ajax и нашел рабочий код
Первый Загрузить библиотеку nusoap из Здесь
затем создайте server.php
<?php
//call library
require_once ('lib/nusoap.php');
// Define the TriangleArea method as a PHP function
function TriangleArea($b, $h) { return 'The triangle area is: ' .(($b*$h)/2); }
// Define the RectangleArea method as a PHP function
function RectangleArea($L, $l) { return 'The rectangle area is: ' .($L*$l); }
// create the function
function get_message($your_name)
{
if(!$your_name){
return new soap_fault('Client','','Put Your Name!');
}
$result = "Welcome to ".$your_name .". Thanks for Your First Web Service Using PHP with SOAP";
return $result;
}
//using soap_server to create server object
$server = new soap_server;
// Initialize WSDL support
$server->configureWSDL('mathwsdl', 'urn:mathwsdl');
// Register the TriangleArea method
$server->register('TriangleArea', // method name
array('b' => 'xsd:int', 'h' => 'xsd:int'), // input parameters
array('area_t' => 'xsd:string'), // output parameters
'urn:mathwsdl', // namespace
'urn:mathwsdl#TriangleArea', // soapaction
'rpc', // style
'encoded', // use
'1=> : Calculate a triangle area as (b*h)/2' // documentation
);
// Register the RectangleArea method to expose
$server->register('RectangleArea', // method name
array('L' => 'xsd:int', 'l' => 'xsd:int'), // input parameters
array('area_r' => 'xsd:string'), // output parameters
'urn:mathwsdl', // namespace
'urn:RectangleAreawsdl#RectangleArea', // soapaction
'rpc', // style
'encoded', // use
'2=> : Calculate a rectangle area as (L*l)' // documentation
);
// Register the RectangleArea method to expose
$server->register('get_message', // method name
array('nm' => 'xsd:string'), // input parameters
array('area_r' => 'xsd:string'), // output parameters
'urn:mathwsdl', // namespace
'urn:get_messagewsdl#get_message', // soapaction
'rpc', // style
'encoded', // use
'3=> : Print a Message as name' // documentation
);
if ( !isset( $HTTP_RAW_POST_DATA ) ) $HTTP_RAW_POST_DATA =file_get_contents( 'php://input' );
$server->service($HTTP_RAW_POST_DATA);
// create HTTP listener
//$server->service($HTTP_RAW_POST_DATA);
exit();
?>
после этого создайте client.php
<code><?php
require_once ('lib/nusoap.php');
//Give it value at parameter
$param = array( 'your_name' => 'Monotosh Roy');
//Create object that referer a web services
$client = new soapclient('http://localhost:81/WebServiceSOAP/server.php?wsdl', true);
// Check for an error
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Constructor error</h2><pre>' . $err . '
';
// На данный момент вы знаете какие-либо звонки
// методы этого веб-сервиса потерпят неудачу
}
// Вызвать метод TriangleArea SOAP
$ result = $ client-> call ('TriangleArea',
массив ('b' => 10, 'h' => 15));
// Проверка на неисправность
if ($ client-> fault) {
echo '
Fault
';
print_r($result);
echo '
';
} еще {
// Проверка на ошибки
$ err = $ client-> getError ();
if ($ err) {
// Показать ошибку
echo '
Ошибка
' . $err . '
';
} еще {
// Показать результат
echo '
Результат
';
print_r($result);
echo '
';
}
}
// Вызываем метод RectangleArea SOAP
$ result = $ client-> call ('RectangleArea',
массив ('L' => 40, 'l' => 20));
// Проверка на неисправность
if ($ client-> fault) {
echo '
Fault
';
print_r($result);
echo '
';
} еще {
// Проверка на ошибки
$ err = $ client-> getError ();
if ($ err) {
// Показать ошибку
echo '
Error
' . $err . '
';
} еще {
// Показать результат
echo '
Результат
';
print_r($result);
echo '
';
}
}
// Показать запрос и ответ
/ * echo '
Request
';
echo '
' . htmlspecialchars($client->request,
ENT_QUOTES) . '
';
echo '
Response
';
echo '
' . htmlspecialchars($client->response,
ENT_QUOTES) . '
'; * /
// Вызов функции на сервере и отправка параметров
$ response = $ client-> call ('get_message', $ param);
// Обработка результата
если ($ client-> вина)
{
echo "
FAULT:
Код: (". $ client-> errorcode. "
";
echo "String:". $ client-> faultstring;
}
еще
{
echo $ response;
}
?>
<! DOCTYPE html PUBLIC "- // W3C // DTD XHTML 1.0 Transitional // EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Веб-сервис SOAP и AJAX
Использование веб-сервисов через вызовы SOAP-AJAX
ajaxSOAP.js файл содержит
var xhrTimeout=100;
function myAjax(){
var l_var = document.getElementById("l_id").value;
var L_var = document.getElementById("L_id").value;
var soapMessage ='<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 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:tns="urn:mathwsdl"> <SOAP-ENV:Body><tns:RectangleArea xmlns:tns="urn:mathwsdl"><L xsi:type="xsd:int">'+L_var+'</L><l xsi:type="xsd:int">'+l_var+'</l></tns:RectangleArea></SOAP-ENV:Body></SOAP-ENV:Envelope>';
var url='http://localhost:81/WebServiceSOAP/server.php';
if(window.XMLHttpRequest) {
httpRequest=new XMLHttpRequest();
}
else if (window.ActiveXObject) {
httpRequest=new ActiveXObject("Microsoft.XMLHTTP");
}
httpRequest.open("POST",url,true);
if (httpRequest.overrideMimeType) {
httpRequest.overrideMimeType("text/xml");
}
httpRequest.onreadystatechange=callbackAjax;
httpRequest.setRequestHeader("Man","POST http://localhost:81/WebServiceSOAP/server.php HTTP/1.1")
httpRequest.setRequestHeader("MessageType", "CALL");
httpRequest.setRequestHeader("Content-Type", "text/xml");
httpRequest.send(soapMessage);
}
function callbackAjax(){
try {
if(httpRequest.readyState==4) {
if(httpRequest.status==200) {
clearTimeout(xhrTimeout);
resultDiv=document.getElementById("resultDiv");
resultDiv.style.display='inline';
resultDiv.innerHTML='<font color="#cc0000" size="4"><b>'+httpRequest.responseText+'</b></font>';
}
}
} catch(e) {
alert("Error!"+e);
}
}