我很难从PHP站点使用安全的WCF Web服务.我在PHP方面的知识是有限的,我在网上找到了各种各样的例子但是没有成功使它们工作.
我有一个Silverlight应用程序也使用此WebService,它工作正常.但是当我运行PHP站点时,我收到此错误:
MessageSecurityException:安全性处理器无法在消息中找到安全标头.这可能是因为消息是不安全的故障,或者因为通信方之间存在绑定不匹配.如果为安全性配置服务且客户端未使用安全性,则会发生这种情况.
我还尝试将customBinding更改为basicHttpBinding.当我这样做时,不再调用自定义用户名验证器.但是,使用basicHttpBinding并删除我的WCF服务上的凭据验证"工作"(除了它是不安全的事实).所以这个问题似乎与安全信息有关.
有人可以给我一个工作示例或教程,可以帮助我使这个PHP页面工作吗?
这是我的PHP代码:
$options = array(
'soap_version' => SOAP_1_1,
'exceptions' => true,
'trace' => 1,
'cache_wsdl' => WSDL_CACHE_NONE,
'Username' => 'MyUserName',
'password' => 'MyPassword');
$client = new SoapClient('https://UrlToService/Service.svc?wsdl', $options);
try
{
$phpresponse = $client->Get();
print $phpresponse->GetResult->Version;
echo "</b><BR/><BR/>";
}
catch(Exception $e)
{
echo "<h2>Exception Error!</h2></b>";
echo $e->getMessage();
echo "<BR/><BR/>";
}
Run Code Online (Sandbox Code Playgroud)
WCF配置
<behavior name="sslBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="MyNamespace.ServiceUserNameValidator, MyNamespace" />
</serviceCredentials>
<serviceSecurityAudit
auditLogLocation="Application"
serviceAuthorizationAuditLevel="Failure"
messageAuthenticationAuditLevel="Failure"
suppressAuditFailure="true" />
</behavior>
<customBinding>
<binding name="sslCustomBinding"> …Run Code Online (Sandbox Code Playgroud) 我正在开发一个PHP脚本,它通过SOAP连接处理大量数据.如果脚本没有遇到任何错误,则估计脚本的总运行时间为几天.我遇到的问题是脚本将运行一段时间,从一小时到一天,然后SOAP连接将因错误而死亡"error fetching http headers".
我见过很多文章建议增加default_socket_timeout设置,我试过这个.它没有帮助.我知道它正在工作,因为它在失败之前至少进行了一百次成功的调用.有什么办法可以阻止这个错误吗?
更新
我打印出请求和响应标头,希望在那里看到错误.但它看起来很好:
HTTP/1.1 200 OK
日期:2013年9月25日星期三21:00:12 GMT
服务器:Apache/2.2.15(CentOS)
X-Powered-By:PHP/5.3.3
内容长度:516
连接:关闭
内容类型:text/xml; 字符集= UTF-8
就示例代码而言,实际脚本很疯狂,但基本前提是:
ini_set('default_socket_timeout', 120);
$client = new SoapClient($wsdl,array(
'trace' =>true,
'connection_timeout' => 500000,
'cache_wsdl' => WSDL_CACHE_BOTH,
'keep_alive' => true,
));
while(!$finished) {
$finished = $client->someSoapFunction($data);
}
Run Code Online (Sandbox Code Playgroud)
someSoapFunction()将返回100个连接的有效数据,然后随机返回上述错误.它运行的时间少于任何一个设置的超时.我的php或apache错误日志中没有错误.我很难过.