繁体   English   中英

SoapClient php用x509证书连接WCF服务

[英]SoapClient php connect WCF services with x509 certificate

我在PHP中使用SoapClient连接WS .NET。 这是wsdl的一部分:

<wsa10:EndpointReference>
<wsa10:Address>-------------</wsa10:Address>
<Identity xmlns="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity">
 <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
  <X509Data>
  <X509Certificate>
     hfWyLJxqZRtXrHw4slQBxEU8SGgHhQsYsRS...
  </X509Certificate>
  </X509Data>
 </KeyInfo>
</Identity>
</wsa10:EndpointReference>

这是我的连接代码:

$client = new SoapClient($wsdl,  array('soap_version' => SOAP_1_2, 'login' => 'login', 'password'=>'password' , 'trace' => 1));
$auth = new stdClass();
$auth->ecodedValue = $hash;
$header = new SoapHeader('http://schemas.xmlsoap.org/ws/2006/02/addressingidentity', 'identity', $auth, false);
$client->__setSoapHeaders($header);

和xml将像这样生成:

<?xml version="1.0" encoding="UTF-8"?> 
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://tempuri.org/" xmlns:ns2="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity">
<env:Header>
<ns2:identity>
 <encodedValue>MIIEvjC</encodedValue>  
</ns2:identity>
</env:Header>
<env:Body>
<ns1:GetBalanceByPhoneNumber> 
<ns1:phoneNumber>------------</ns1:phoneNumber>
</ns1:GetBalanceByPhoneNumber>
</env:Body>
</env:Envelope>

我应该生成哪种格式的xml以通过WS证书? 我正在等待您的帮助:(。谢谢!

您可以使用OPTION“ local_cert”随SSL请求一起提供SSL证书:

$client = new SoapClient($wsdl,  array(
   'local_cert' => '/path/to/your/certificate.pem',
   'soap_version' => SOAP_1_2, 
   'login' => 'login', 
   'password'=>'password' , 
   'trace' => 1,
));

http://php.net/manual/zh/soapclient.soapclient.php上检查SOAP OPTIONS的参数。

您还可以通过创建流上下文来关闭SSL验证,如下所示:

$context = stream_context_create(array(
    "ssl" => array(
        "verify_peer" => false,
        "allow_self_signed" => true,
    ),
    "https" => array(
        "curl_verify_ssl_peer" => false,
        "curl_verify_ssl_host" => false,
    ),
));


$options = array(
    "stream_context" => $context,
    "features" => SOAP_SINGLE_ELEMENT_ARRAYS,
    // "cache_wsdl" => WSDL_CACHE_NONE,
    // "trace" => true,
    // "exceptions" => true,
);

$client = new SoapClient("https://www.myhost.com/service?ws", $options);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM