我创建了简单的SOAP API,如下所述。
catalog.wsdl
<?xml version ='1.0' encoding='UTF-8' ?>
<definitions name='Catalog'
targetNamespace='http://example.org/catalog'
xmlns:tns=' http://example.org/catalog '
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='getUserRequest'>
<part name='catalogId' type='xsd:string'/>
</message>
<message name='getUserResponse'>
<part name='Result' type='xsd:string'/>
</message>
<portType name='UserPortType'>
<operation name='getUser'>
<input message='tns:getUserRequest'/>
<output message='tns:getUserResponse'/>
</operation>
</portType>
<binding name='UserBinding' type='tns:UserPortType'>
<soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http' />
<operation name='getUser'>
<soap:operation soapAction='urn:localhost-user#getUser'/>
<input>
<soap:body use='encoded' namespace='urn:localhost-user' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
</input>
<output>
<soap:body use='encoded' namespace='urn:localhost-user' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
</output>
</operation>
</binding>
<service name='UserService'>
<port name='UserPort' binding='UserBinding'>
<soap:address location='http://localhost/soap/soap-server.php'/>
</port>
</service>
皂server.php
function getUser($catalogId) {
if($catalogId=='catalog1'){
return "hello";
}
}
ini_set("soap.wsdl_cache_enabled", "0");
$server = new SoapServer("catalog.wsdl");
$server->addFunction("getUser");
$server->handle();
皂client.php
$client = new SoapClient('catalog.wsdl');
$catalogId='catalog2';
$response = $client->getUser($catalogId);
echo $response;
现在我想在此添加SOAP身份验证。怎么做?任何人都可以提供代码吗?