Last active
September 8, 2019 23:09
-
-
Save lighth7015/ffbcfe216419010e37643bcc2a58eccc to your computer and use it in GitHub Desktop.
PHP soap client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class UserCredentials { | |
public $Username; | |
public $Password; | |
public function __construct( $username, $password ) { | |
$this->Username = $username; | |
$this->Password = $password; | |
} | |
} | |
class Document { | |
private $instance; | |
public function __construct(string $version = '1.0') { | |
$document = $this->instance = | |
new DomDocument( $version ); | |
$document->preserveWhiteSpace = false; | |
$document->formatOutput = true; | |
} | |
public function parse( string $document ): String { | |
$this->instance->loadXML( $document ); | |
return $this->instance->saveXML(); | |
} | |
} | |
$accountId = ""; | |
$document = new Document; | |
$options = [ | |
'features' => SOAP_SINGLE_ELEMENT_ARRAYS, | |
'exceptions' => false, | |
'trace' => 1 | |
]; | |
// Create the SoapClient instance | |
$url = "https://mws.envisionrx.com/rxfunctions.asmx?WSDL"; | |
$client = new SoapClient( $url, $options ); | |
// Create the header | |
$args = []; | |
$client->__setSoapHeaders([ | |
new SoapHeader( | |
"http://mws.envisionrx.com", | |
"UserCredentials", | |
new UserCredentials( "Username", "Password" ), | |
false) | |
]); | |
// Call SOAP service | |
$response = $client | |
->GetBrandEquivalentByGenericNDC(); | |
printf( "SOAP request:\n" ); | |
printf( "%s\n", $document->parse( $client->__getLastRequest())); | |
var_dump( $response ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment