Skip to content

Instantly share code, notes, and snippets.

@lighth7015
Last active September 8, 2019 23:09
Show Gist options
  • Save lighth7015/ffbcfe216419010e37643bcc2a58eccc to your computer and use it in GitHub Desktop.
Save lighth7015/ffbcfe216419010e37643bcc2a58eccc to your computer and use it in GitHub Desktop.
PHP soap client
<?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