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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?