douqi3913 2018-11-06 13:36
浏览 41

带有私钥和wsdl的SOAP请求

I require some help. I've been wrapping my head around this one.

I have:

  • Private KeyStore file (crt)
  • Local WSDL file

I need to make a SOAP request, I assume WSDL stands for function take in's..

My code as it follows:

    $opts = array(
        'ssl' => array(
            'ciphers'=>'RC4-SHA', 
            'verify_peer'=>false, 
            'verify_peer_name'=>false,
            'allow_self_signed' => true
        )
    );
    // SOAP 1.2 client
    $params = array (
        'encoding' => 'UTF-8', 
        'verifypeer' => false, 
        'verifyhost' => false, 
        'soap_version' => SOAP_1_2, 
        'trace' => true, 
        'exceptions' => true, 
        'connection_timeout' => 1,
        "local_cert" => "localpem.pem",
        "passphrase" => "somepassword123",
        'stream_context' => stream_context_create($opts) 
    );

    $ns_wsse = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
    $password_type = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText';
    $soap_env = 'http://schemas.xmlsoap.org/soap/envelope/';
    $header = new SimpleXMLElement('<Header/>');
    $header->registerXPathNamespace('wsse', $ns_wsse);
    $soap_root = $header->addChild('header');
    $security = $soap_root->addChild('wsse:Security', null, $ns_wsse);
    $usernameToken = $security->addChild('wsse:UsernameToken', null, $ns_wsse);
    $usernameToken->addChild('wsse:Username', "someUsername", $ns_wsse);
    $usernameToken->addChild('wsse:Password', "somepassword123", $ns_wsse)->addAttribute('Type', $password_type);
    $auth = $header->xpath('/Header/header')[0]->asXML();

    $soap_client = new SoapClient('localwsdlfile.wsdl', $params);
    $soap_client->__setSoapHeaders(new SoapHeader($ns_wsse, 'Security', new SoapVar($auth, XSD_ANYXML), true));
    $soap_client->__setLocation('https://service-site/services/someservice');

I use this to call it.

$tst = $soap_client->getSomeValuesFunc(array('date' => '2000-02-02 2 02:02:02'));

 } catch(SoapFault $exception)
 {
    echo $exception->getMessage(), '<br />', $exception->getTraceAsString();
 }

It drops me

Could not connect to host
#0 [internal function]: SoapClient->__doRequest('__call('...

And this "Could not connect to host" is such a broad way of sayng somethings wrong, now I am wondering what can couse this issue.

I assume I am generating my certification incorrectly? Since I need to keystore a password to it. So what I did I keystored a cert form crt -> jks and then got jks to pem file so it would be attached.

What else can encourage connection errors on my code?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?