简体   繁体   English

PHP SOAP请求不使用WSDL

[英]PHP SOAP request not working with WSDL

I'm trying to use a SOAP service called Chaverweb. 我正在尝试使用名为Chaverweb的SOAP服务。 I have their WSDL; 我有他们的WSDL; it's here . 它在这里

When I try to make a simple request like GetCWVersion , it's working, but whenever I try to request a function that would need some sort of authentication, like Get_Syn_Comsend (getting an institute's details), it doesn't work. 当我尝试发出像GetCWVersion这样的简单请求时,它正在工作,但每当我尝试请求某种需要某种身份验证的函数时,比如Get_Syn_Comsend (得到一个机构的详细信息),它就不起作用了。

I tried setting AuthHeader as specified in the WSDL, but it's not working. 我尝试按照WSDL中的指定设置AuthHeader ,但它不起作用。

Here's my code. 这是我的代码。 I'm hoping there's something obvious I'm not doing since this is my first time working with SOAP: 我希望有一些显而易见的事情我没有做,因为这是我第一次使用SOAP:

try {
    $soapClient = new SoapClient('https://www.chaverweb.net/Synagogue.asmx?WSDL');
    $header = new SoapHeader('https://www.chaverweb.net/webservices/', 'AuthHeader', array("Username"=>"xx@yy.com", "Password"=>"...", "SynKey"=>"..."), false);
    $header2 = new SoapHeader('https://www.chaverweb.net/webservices/', 'SFHeader', array("sf"=>""), false);


    $soapClient->__setSoapHeaders(array($header, $header2));
    $versionResponse = $soapClient->Get_Syn_Comsend();
    print_r($versionResponse);
} catch (SoapFault $exception) {
    echo "Exception: " . $exception->getMessage();
}

This, by the way, gives me: stdClass Object ( ) Thank you very much! 顺便说一句,这给了我:stdClass Object()非常感谢你!

so I did some direct testing and it is very simple: 所以我做了一些直接测试,非常简单:

INVALID LOGIN is being returned on the WSDL. WSDL上返回了INVALID LOGIN。

http://phpfiddle.org/main/code/3pvp-8wi9 http://phpfiddle.org/main/code/3pvp-8wi9

You can view my code and testing here. 您可以在此查看我的代码和测试。 While you are testing use their bulit in TestFunction() instead of the function you want to run, this way you can see where the error is. 在测试时,在TestFunction()中使用它们的bulit而不是你想要运行的函数,这样你就可以看到错误的位置。 Let me know how I can be of more assistance. 让我知道如何能获得更多帮助。

BEFORE EDIT, THIS WAS MY RESPONSE: 在编辑之前,这是我的回应:

You first need to make sure that the last request you sent to complete the function has no errors. 首先需要确保为完成该功能而发送的最后一个请求没有错误。 As well check that the response was received. 还要检查是否收到了回复。 This may help debug why you are getting this to begin with. 这可能有助于调试您开始使用它的原因。 Just add these two lines of code and let us know what you see: 只需添加这两行代码,让我们知道您所看到的内容:

print_r($soapClient->__getLastRequest());
print_r($soapClient->__getLastResponse());

The key here is to make sure you are receiving the response correctly. 这里的关键是确保您正确收到回复。 Post this response and I will gladly help you debug it. 发布此回复,我很乐意帮助您调试它。

Just food for thought, here is how I would set up this request (this is NOT tested) but the definition in your wsdl shows you need to be using literal and SoapClient does not always use the correct document type when interpreting the response: 只是值得深思,这是我如何设置这个请求(这是未经过测试的),但是你的wsdl中的定义显示你需要使用文字,SoapClient在解释响应时并不总是使用正确的文档类型:

ini_set("soap.wsdl_cache_enabled", "0");
try {
$options = array('trace'=>1,
                 'exceptions'=> 1,
                 'style'=> SOAP_DOCUMENT,
                 'use'=> SOAP_LITERAL 
                ); 

$soapClient = new SoapClient('https://www.chaverweb.net/Synagogue.asmx?WSDL',$options);
$header = new SoapHeader('https://www.chaverweb.net/webservices/', 'AuthHeader', array("Username"=>"ofer.ungar@gmail.com", "Password"=>"demo1234!", "SynKey"=>"T21982011213"), false);
    $header2 = new SoapHeader('https://www.chaverweb.net/webservices/', 'SFHeader', array("sf"=>""), false);


    $soapClient->__setSoapHeaders(array($header, $header2));
    $versionResponse = $soapClient->Get_Syn_Comsend();

    print_r($versionResponse->Get_Syn_ComsendSoapOut);

    } catch (SOAPFault $f) {
     print $f;
    }

Hope this helps in some way! 希望这在某种程度上有所帮助! Send your results for further assistance :) 发送结果以获得进一步的帮助:)

POST EDIT FOR SIMPLEXML TEST: replace: 用于SIMPLEXML TEST的POST编辑:替换:

print_r($versionResponse->Get_Syn_ComsendSoapOut);

with this: 有了这个:

$data = simplexml_load_file($versionResponse->Get_Syn_ComsendSoapOut);
print_r($data);

See what it gives you, hopefully it either throws a descriptive error or it processes the result (very rare, but possible)! 看看它给你的东西,希望它会抛出一个描述性错误或者处理结果(非常罕见,但可能)!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM