从PHP到Microsoft WS的Soap连接

时间:2016-07-11 16:46:44

标签: php web-services soap gp

我需要PHP的等效以下内容

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

我正在传递域名/用户密码

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

然后我找到了这个

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";
    }
}

(有一个支持班,但我认为我不需要发帖)

所以为了测试我的连接,我正在做这个

// 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);

当我运行脚本时,我得到以下内容:

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

有没有办法可以确认我可以使用像hurl.it这样的东西连接?我不知道如何使用该服务处理域名。

我在Mac上,还有另一种方法可以确认我可以连接吗?

0 个答案:

没有答案