php soap API身份验证

php soap API身份验证,php,web-services,soap,wsdl,soap-client,Php,Web Services,Soap,Wsdl,Soap Client,我创建了简单的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/ws

我创建了简单的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>
soap client.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 = new SoapClient('catalog.wsdl');
  $catalogId='catalog2';
  $response = $client->getUser($catalogId);
  echo $response;

现在,我想在这里添加SOAP身份验证。怎么做?有人能给我提供代码吗?

提供一个SOAP服务方法
login
,该方法使用params
username
password
@TiMESPLiNTER:我想你是在谈论创建登录功能和DB身份验证。我想提供HTTP身份验证。你能帮我吗?也许这能帮你:根据这一点,你只需提供一个带有
login
password
元素的数组,并将其作为第二个参数交给
SoapClient
的构造函数。@TiMESPLiNTER:我已经浏览了提供的链接。我想到了如何为登录传递参数,但实际上应该在哪里编写用于身份验证的代码?如果使用apache,可以使用
htaccess
htpasswd
保护API。