【问题标题】:How to integrate PHP code with a WCF web service using Message Security如何使用 Message Security 将 PHP 代码与 WCF Web 服务集成
【发布时间】:2018-05-07 10:33:08
【问题描述】:

美好的一天。

我想通过 PHP 的 Message Security 与 WCF Web 服务集成。 Web 服务需要来自客户端的证书(PHP 代码),并且不需要任何用户名或密码。它还使用 wsHttpBinding。 我有一台运行 IIS7 的 Windows x64 电脑,我可以从我的浏览器执行 php 代码。

我尝试在 PHP 中使用 SoapClient() 和以下代码:

<?php

ini_set("soap.wsdl_cache_enabled", "0");

try
{
    $context = stream_context_create(["ssl" => ["local_cert" => "./cert/TestClient.pem", "CN_Name => CN=TestClient"]]);
    $options = ["soap_version" => SOAP_1_2, "authentication" => SOAP_AUTHENTICATION_DIGEST, "context" => $context];
    $service = new SoapClient("http://vanzyld:49321/pointerws/?wsdl", $options);

    $service->GetVehicleList([3538]);
}
catch (SOAPFault $f) 
{
    error_log('ERROR => '.$f);
}

?>

但是,

对于 SOAP_1_2,这是调用返回的错误:

ERROR => SoapFault exception: [HTTP] Error Fetching http headers in C:\inetpub\phproot\WebService\GetVehicles.php:16
Stack trace:
#0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://vanzyld:...', 'http://pointers...', 2, 0)
#1 C:\inetpub\phproot\WebService\GetVehicles.php(16): SoapClient->__call('GetVehicleList', Array)
#2 {main}

使用 SOAP_1_1,返回这个。

ERROR => SoapFault exception: [HTTP] Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'. in C:\inetpub\phproot\WebService\GetVehicles.php:16
Stack trace:
#0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://vanzyld:...', 'http://pointers...', 1, 0)
#1 C:\inetpub\phproot\WebService\GetVehicles.php(16): SoapClient->__call('GetVehicleList', Array)
#2 {main}

经过大量研究,SoapClient 似乎无法很好地处理对实现 Message Security 的 WCF Web 服务的调用。 其中一个建议是(来自这里:How to communicate between PHP and WCF securely)我从 WSO2 安装第 3 方包,但这似乎也不是最好的方法,因为 WSO2 不再支持这个。即使按照有关如何在我的 PC 上安装 wsf 的所有步骤进行操作,我也无法在我的 PC 上安装 WSF。 (https://wso2.com/project/wsf/php/2.0.0/docs/install_guide.html - 我按照步骤 2.1 和 2.4 进行操作) WSF 部分从未在我的 phpinfo 页面上弹出,因为它已启用。安装 WSF 后返回的 PHP 错误,只是代码找不到 WSClient() 类。

是否有任何其他 PHP 类或库或第三方对象可用于成功地将 PHP 代码与使用 Message Security 的 WCF Web 服务集成?或者有没有办法让 SoapClient() 实际使用这种 WCF 服务?还是 PHP 在与 Message Security WCF Web 服务的集成能力方面受到限制?

谢谢。 达琳

【问题讨论】:

    标签: php windows wcf wcf-security


    【解决方案1】:

    在这两种情况下,您的标题似乎都有错误。 SOAP_1_2 错误明确告诉您这一点,SOAP_1_1 错误抱怨设置了错误的内容类型,这意味着实际上没有正确发送内容类型标头。

    尝试使用SoapHeader 类来修复您的代码:

    http://php.net/manual/en/class.soapheader.php

    【讨论】:

    • 我认为这里的问题是 PHP 不支持带有 Message Security 的 WCF Web 服务。
    猜你喜欢
    • 2014-04-14
    • 2016-06-04
    • 2014-09-15
    • 1970-01-01
    • 1970-01-01
    • 2014-12-05
    • 2015-10-21
    • 2021-02-05
    • 1970-01-01
    相关资源
    最近更新 更多