2

I need the equivalent of the following for PHP

    System.Net.NetworkCredential credential = new System.Net.NetworkCredential("administrator", "PASSWORD", "DOMAIN");
    wsDynamicsGP.Credentials = credential;
    DynamicsGPWebService.Policy apPolicy = wsDynamicsGP.GetPolicyByOperation("CreatePayablesInvoice", context);

I am passing domain/user password

define('USERPWD', 'domain\username:password');

I then found this

class NTLMSoapClient extends SoapClient {
    function __doRequest($request, $location, $action, $version) {
        $headers = array(
            'Method: POST',
            'Connection: Keep-Alive',
            'User-Agent: PHP-SOAP-CURL',
            'Content-Type: text/xml; charset=utf-8',
            'SOAPAction: "'.$action.'"',
        );
        $this->__last_request_headers = $headers;
        $ch = curl_init($location);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_POST, true );
        curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
        curl_setopt($ch, CURLOPT_USERPWD, USERPWD);
        $response = curl_exec($ch);
        return $response;
    }

    function __getLastRequestHeaders() {
        return implode("\n", $this->__last_request_headers)."\n";
    }
}

(There is a supporting class but I don't think I need to post it)

So to test my connection I am doing this

// we unregister the current HTTP wrapper 
stream_wrapper_unregister('http');
// we register the new HTTP wrapper 
stream_wrapper_register('http', 'NTLMStream') or die("Failed to register protocol");

// Initialize Soap Client 
$baseURL = 'http://www.targetgpserver.com:port';
$client = new NTLMSoapClient($baseURL.'/DynamicsGPWebServices/DynamicsGPService.asmx?wsdl');
print_var($client);

When I run the script I get the following:

PHP Fatal error:  SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://erpweb.treecarescience.com:48620/DynamicsGPWebServices/DynamicsGPService.asmx' : Document is empty

Is there a way I can confirm I can connect using something like hurl.it? I am not sure how to handle the domain using that service.

I am on a Mac, is there another way to confirm that I can connect?

markalex
  • 8,623
  • 2
  • 7
  • 32
brentwpeterson
  • 162
  • 2
  • 9

0 Answers0