我有一个关于用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