PHP Classes पर, रोजर Veciana मैं Rovira प्रस्तुत इस (मैं सिर्फ कोड पुन: स्वरूपित):,
class WSSoapClient extends SoapClient {
private $username;
private $password;
/*Generates de WSSecurity header*/
private function wssecurity_header() {
/* The timestamp. The computer must be on time or the server you are
* connecting may reject the password digest for security.
*/
$timestamp = gmdate('Y-m-d\TH:i:s\Z');
/* A random word. The use of rand() may repeat the word if the server is
* very loaded.
*/
$nonce = mt_rand();
/* This is the right way to create the password digest. Using the
* password directly may work also, but it's not secure to transmit it
* without encryption. And anyway, at least with axis+wss4j, the nonce
* and timestamp are mandatory anyway.
*/
$passdigest = base64_encode(
pack('H*',
sha1(
pack('H*', $nonce) . pack('a*',$timestamp).
pack('a*',$this->password))));
$auth = '
<wsse:Security SOAP-ENV:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.'.
'org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>'.$this->username.'</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-'.
'wss-username-token-profile-1.0#PasswordDigest">'.$passdigest.'</wsse:Password>
<wsse:Nonce>'.base64_encode(pack('H*', $nonce)).'</wsse:Nonce>
<wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-'.
'200401-wss-wssecurity-utility-1.0.xsd">'.$timestamp.'</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
';
/* XSD_ANYXML (or 147) is the code to add xml directly into a SoapVar.
* Using other codes such as SOAP_ENC, it's really difficult to set the
* correct namespace for the variables, so the axis server rejects the
* xml.
*/
$authvalues = new SoapVar($auth,XSD_ANYXML);
$header = new SoapHeader("http://docs.oasis-open.org/wss/2004/01/oasis-".
"200401-wss-wssecurity-secext-1.0.xsd", "Security", $authvalues,
true);
return $header;
}
/* It's necessary to call it if you want to set a different user and
* password
*/
public function __setUsernameToken($username, $password) {
$this->username = $username;
$this->password = $password;
}
/* Overwrites the original method adding the security header. As you can
* see, if you want to add more headers, the method needs to be modifyed
*/
public function __soapCall($function_name, $arguments, $options=null,
$input_headers=null, $output_headers=null) {
$result = parent::__soapCall($function_name, $arguments, $options,
$this->wssecurity_header());
return $result;
}
}
मैंने देखा है इस संस्करण 1.0 के लिए है, लेकिन उम्मीद है कि यह सही रास्ते पर डाल देंगे। – Artefacto
धन्यवाद जवाब देना के लिए, अब मैं अगले अपवाद Uncaught SoapFault अपवाद मिल गया है: [HTTP] संदेश क्योंकि सामग्री प्रकार 'text/xml प्रोसेस नहीं कर सकता; charset = utf-8 'था नहीं की उम्मीद प्रकार' आवेदन/साबुन + xml; charset = utf-8 '। /home/projects/caheritage/site/providence/app/lib/core/WSSoapClient.php:80 में किसी भी विचार कैसे इसे हल करने की? –
wsHttpBinding (सोप 1.2) 'आवेदन/साबुन + xml' सामग्री प्रकार का उपयोग करता है, basicHttpBinding (सोप 1.1) का उपयोग करता है 'text/xml' तो सुनिश्चित करें कि आपके PHP और WCF मैच बनाते हैं। यानी - सुनिश्चित करें कि पीएचपी जब या तो एक बुनियादी या ws WCF में बाध्यकारी बुला सही सोप संस्करण का उपयोग करने के लिए निर्धारित है – Xcalibur