我有一個關於用PHP編寫的web服務的問題。在.NET客戶端上使用PHP webservice的問題
要實例SoapClient
使用PHP,我通過以下參數對SoapClient
方法在PHP這樣的:
$client = new SoapClient("some.wsdl",
array('login' => "some_name",
'password' => "some_password"
));
要調用與PHP web服務方法,能正常工作。但是我的同事在使用.NET發送證書時遇到了問題。
有誰知道這是如何通過.NET?
更新,淨客戶端配置
<basicHttpBinding>
<binding name="webserviceControllerBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic"/>
</security>
</binding>
</basicHttpBinding>
而在代碼:
client.ClientCredentials.UserName.UserName = "username";
client.ClientCredentials.UserName.Password = "password";
更新2:
建立所述客戶端(在PHP)
$client = new
SoapClient("http://***.***.***/********/httpdocs/webservice/wsdl?wsdl",
array(
'uri' => "http://***.***.***/***/httpdocs/webservice/webservice",
'login' => "*****",
'password' => "*****"
));
處理請求並引用該類的服務器。
public function webservice()
parent::__construct();
ini_set('soap.wsdl_cache_enabled', 0);
$this->presenter = "NONE";
$server = new SoapServer("http://***.***.***/***/httpdocs/webservice/wsdl?wsdl", array('uri' => "http://***.***.***/"));
$server->setClass( "Model_Webservice");
$server->handle();
而webservice類中的這一塊處理用戶名和密碼認證。
class Model_Webservice extends Object_Database
{
public function __construct()
{
parent::__construct();
$accesslog = Log::factory('file', $this->config->log->access , 'ACCESS LOG');
if(!isset($_SERVER['PHP_AUTH_USER']) || trim($_SERVER['PHP_AUTH_USER']) == "")
{
$accesslog->log("[denied] [soapclient " . $_SERVER['REMOTE_ADDR'] . "] no username supplied");
throw new SOAPFault("Authentication failed - reason: no username supplied", 401);
}
elseif(!isset($_SERVER['PHP_AUTH_PW']) || trim($_SERVER['PHP_AUTH_PW']) == "")
{
$accesslog->log("[denied] [soapclient " . $_SERVER['REMOTE_ADDR'] . "] no password supplied");
throw new SOAPFault("Authentication failed - reason: no password supplied", 401);
}
else
{
$user = new User(null, $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
if($user->getId() > 0)
{
$accesslog->log("[approved] [soapclient " . $_SERVER['REMOTE_ADDR'] . "] User logged in");
}
if(!$user->getId() > 0)
{
$accesslog->log("[denied] [soapclient " . $_SERVER['REMOTE_ADDR'] . "] incorrect username and password combination");
throw new SOAPFault("Authentication failed - reason: incorrect username and password combination", 401);
}
}
}
更新3
我基於調整後的配置收到以下錯誤消息
<bindings>
<basicHttpBinding>
<binding name="webserviceControllerBinding">
<security mode="Message">
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
BasicHttp結合要求BasicHttpBinding.Security.Message.ClientCredentialType相當於用於安全消息的BasicHttpMessageCredentialType.Certificate憑證類型。 爲UserName憑證選擇Transport或TransportWithMessageCredential安全性。'
我不想使用證書或https。
他們如何指定的憑據和你使用的身份驗證機制? – jgauffin
我必須說,如果我關閉PHP服務器的安全性,我們可以使用.NET調用Web服務。但是,這是其他程序員使用: <綁定名稱= 「webserviceControllerBinding」> <安全模式= 「TransportCredentialOnly」> <傳輸clientCredentialType = 「基本」/> basicHttpBinding的> client.ClientCredentials .UserName.UserName =「username」; client.ClientCredentials.UserName.Password =「password」; –
總是添加代碼作爲您問題的更新。否則將不可能遵循它。 – jgauffin