您的位置:首页 > 编程语言 > PHP开发

php webservice 验证 另一方式

2011-03-31 16:54 204 查看
这是csdn 的帖子内容 自己留着了 感觉这种方式不太正规 但可用

client_1.php

<?php
$re=$soapClient = new SoapClient("http://test.cheshi.com/webservice/server_1.php?wsdl",array("login"=>"admin","password"=>"123456"));

echo $soapClient->hw('hello','world');
?>


server_1.php

<?php
error_reporting(2047);
ini_set("soap.wsdl_cache_enabled", "0");
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) ||
!($_SERVER['PHP_AUTH_USER']=='admin' && $_SERVER['PHP_AUTH_PW']=='123456')) {
header('WWW-Authenticate: Basic realm="WEBSERVICE"');
header("HTTP/1.0 401 Unauthorized");
echo "You must enter a valid login ID and password to access this resource/n";
die;
}
class serverClass
{
function hw($name,$pass)
{
return $name." ".$pass;
}
}
$soapServer = new SoapServer("hello.wsdl");
$soapServer->setClass('serverClass');
$soapServer->handle();

?>


hello.wsdl

<?xml version ='1.0' encoding ='UTF-8' ?>
<definitions name='lake' targetNamespace='http://test.cheshi.com/webservice/' xmlns:tns='http://test.cheshi.com/webservice/' xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/' xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/' xmlns='http://schemas.xmlsoap.org/wsdl/'>

<message name='getRequest'>
<part name='name' type='xsd:string'/>
<part name='pass' type='xsd:string'/>
</message>

<message name='getResponse'>

<part name='Result' type='xsd:string'/>
</message>

<portType name='class'>
<operation name='hw'>
<input message='tns:getRequest'/>
<output message='tns:getResponse'></output>
</operation>
</portType>

<binding name='class' type='tns:class'>
<soap:binding style="rpc" mce_style="rpc" transport='http://schemas.xmlsoap.org/soap/http'/>
<operation name='hw'>
<soap:operation soapAction=''/>
<input>
<soap:body namespace="xmlns:tns" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body namespace="xmlns:tns" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
</binding>

<service name='class'>
<port name='goforsoap' binding='class'>
<soap:address location='http://test.cheshi.com/webservice/server_1.php'/>
</port>
</service>
</definitions>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: