我在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证书?我等你的帮忙:(。谢谢!
答案 0 :(得分:0)
您可以使用OPTION&#34; local_cert&#34;提供SSL证书以及soap请求:
$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/en/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);