I am consuming a third-party webservice and I'm using soapUI to test it. I was advised to load the WSDL, leave it untouchted, then change the endpoint in SOAPUI before executing the calls to the endpoints. This works fine and is behaving as I would expect it to.
I'm now trying to emulate this in PHP but I'm having problems changing the endpoint. I'm loading the WSDL into SOAPCLIENT and then using this command to change the endpoint:
$client->__setLocation($endpointURI);
However this is not acting like I'd expect it to and is giving me a "500:Internal Server Error" response when I the go to make a soap call after modifying the location/endpoint. I'm certain that all other parameters are correct and was wondering if anyone could shed some light on the issue and confirm that doing this 'set location' cmd should be the equivalent of changing the endpoint manually in SOAPUI.
Any ideas/opinions appreciated.
While instantiating SoapClient try to add an array key named 'location' with the new endpoint.
$options = array('login' => 'x', 'password' => 'y', 'location' => $endpointURI);
$client = new SoapClient($address, $options);
Try calling __soapCall with the location override in there:
$result = $this->soap_client->__soapCall('whatever', ['location' => $file_location]);
I'm finding __setLocation is not working while the above workaround does.
Related
I'm working with a SOAP API, and they've disabled the WSDL document that's normally located in the base .asmx URL for SOAP APIs. The page is instead a 404 page when viewed without an XML request. Right now, simply instantiating a SoapClient fails ($soap = new SoapClient($url);, the error is Premature end of data in tag html line 1). I'm assuming here that a new instance of SoapClient tries to retrieve the WSDL from the server. Is there a way of turning this off? Of saying 'I want to use SoapClient, but don't do any calls until I tell you the XML call that you'll be using (along with all required data)'?
EDIT: I've tried setting cache_wsdl to WSDL_CACHE_NONE but I still get that error.
You have to run SoapClient in non-wsdl mode therefore you must set the wsdl parameter of the SoapClient c'tor to null
public SoapClient::SoapClient ( mixed $wsdl [, array $options ] )
Initialize it the following way
$client = new SoapClient(null, array('location' => http://your_domain/your_webservice",
'uri' => "http://namespace_of_the_webservice/"));
location...The location of the webservice
uri...The namespace of the target webservice
I need communicate with web-service construct in .net(i think), but when i try call a method, return this error:
The SOAP action specified on the message, '', does not match the HTTP SOAP Action, 'http://tempuri.org/TripointWebservicesVersionedGeneral/Ping'.
Code to connect to web-service and execute method:
$client = new SoapClient(
'...?wsdl',
array(
'trace' => 1,
'soap_version' => SOAP_1_2
)
);
//$test = $client->__soapCall('Ping',array(''));
$test = $client->Ping();
What is the reason of this error? or what i need to do to call a method?
I have already read this PHP Fatal error: "The SOAP action specified on the message, '', does not match the HTTP SOAP Action", and put in option of soap connection this "'action' => '.../Ping'" but don't help me.
i've found the reason why i can't call the method's, its because of this:
One of the problems:
The PHP returns "Caught exception: Cannot process the message because the content type ‘text/xml; charset=utf-8′ was not the expected type ‘application/soap+xml; charset=utf-8′."
The reason:
WCF is running a new version of web services than expected by the PHP.
The solution:
Change the binding type of the WCF service from binding="wsHttpBinding" to binding="basicHttpBinding".
This insures that your .NET web service would support clients and other services that conform to the WS-I standards.
url source:
http://spacebug.com/php-calling-wcf-part-1-html
Not a full answer, but I just wanted to highlight that you're probably facing this problem because you're using SoapClient to try and consume a web service that uses WS-Addressing. You should try to track down what others do in this situation:
http://www.cdatazone.org/index.php?/archives/15-WS-Addressing-for-extsoap.html
https://github.com/wso2/wsf
I am trying to access a Web Service (SOAP) from a provider. I have not control on the server response. For this I am using, Zend_Soap_Client passing the WDSL and options in the constructor, I can do getFunctions, but when try to access the first Soap method I get
[Sender] looks like we got no XML document
After looking around and checking the answer I get from the server with soapUI I see that the answer is missing the XML declaration:
<?xml version="1.0" encoding="XXXXXXX"?>
So, is there aby way to make the Zend_Soap_Client omit the XML validation based in the XML declaration? Assuming that the lacking of the declaration is my problem.
Here is the code I use for this:
private $_connection_settings = array('login' => self::API_user, 'pwd' => self::API_password, 'key'=> self::API_Key);
private static $CONNEXION_PARAMS = array(
'soap_version' => SOAP_1_1,
'encoding' => 'UTF-8'
);
...
//somewhere in my code:
$client = new Zend_Soap_Client('http://server_URL?wsdl', self::$CONNEXION_PARAMS);
$response = $client->fistSoapMethod($this->_connection_settings);
And response is not assigned.
Thanks!
No other warnings/errors from your code besides the SOAP Fault?
Not sure it is the WSDL. Can always try validating the WSDL using an online tool.
Have you used getLastResponse() and getLastRequest() methods? Sounds like you might be sending some garbage at the start of your request. Another thing I always do when testing is turn off WSDL caching.
ini_set("soap.wsdl_cache_enabled", 0);
I'm trying to use Zend_Soap_Client to communicate with an ASP.net web service. Here's my client call:
$client = new Zend_Soap_Client(null, array(
'location' => 'http://example.com/service.asmx',
'uri' => 'http://example.com/'
));
$user = new UserDetail();
$result = $client->UserDetails($user);
However this always gives me the error:
System.NullReferenceException: Object reference not set to an instance of an object. at Service.UserDetails(UserDetail UserDetail)
some googling revealed that this is quite a common problem. The most common solution seemed to be to pass the parameters as an array, so I tried:
$result = $client->UserDetails(array('UserDetail' => $user));
but this gave the same error. I also tried passing the params as a stdClass object, nesting the array in another with 'params' as the key, and a few other things but the error is always the same.
I have the ASP code for the web service itself, the relevant method is:
public Result UserDetails(UserDetail UserDetail) {
[some stuff]
Hashtable ht = new Hashtable();
ht = UserDetail.GenerateData();
}
the error is caused by the GenerateData() call.
I assume the UserDetails method is getting null instead of my object as the parameter, but I'm not sure how I should be calling the method, or how I can debug this further. The majority of the Zend_Soap_Client examples I've found seem to be using WSDL, which this service is not; not sure if that is relevant. Any help appreciated!
I eventually solved this with:
$userDetails = new UserDetails();
$userDetails->UserDetail = $user;
$client->UserDetails($userDetails);
it seems ASP.net expects (and returns) params to be nested in an object/array with the same name as the method being called.
If you have any possibility to change the asp.net code I'd suggest you try an implementation of the method UserDetails without parameters just to make sure that code isn't broken.
I would then create a consumer-method in asp.net, debug the http-request and see how the userdetail-object is serialized/broken down in array form. Then it's "just" a matter of creating a similar http request from php.
Confluence soap api defines two methods with the same name but different parameters:
Page getPage(String token, long pageId) - returns a single Page (according to the documentation the second parameter is String, but in WSDL it is long)
Page getPage(String token, String spaceKey, String pageTitle) - returns a single Page
I would need to call the method with two parameters using PHP SoapClient. In WSDL mode SoapClient insists on using the three-parameter one. In non-WSDL mode I managed to make a call with two parameters, but I cannot make the type of the second parameter to be long. How can I get the SoapClient to call getPage with two parameters with the correct types?
Here's what I've done so far:
Using SoapClient in WSDL mode...
$soapClient = new SoapClient("http://xxx/confluence/rpc/soap-axis/confluenceservice-v1?wsdl", array("trace" => TRUE));
$token = $soapClient->login(CONFLUENCE_USERNAME, CONFLUENCE_PASSWORD);
$page = $soapClient->getPage($token, $confluence_article_id);
...produces a request for the three-parameter method (only body shown)...
<SOAP-ENV:Body><ns1:getPage><in0 xsi:type="xsd:string">dkjLIx00Ap</in0><in1 xsi:type="xsd:string">24445207</in1><in2 xsi:nil="true"/></ns1:getPage></SOAP-ENV:Body>
...which causes fault:
<faultstring>com.atlassian.confluence.rpc.RemoteException: You're not allowed to view that page, or it does not exist.</faultstring>
The page with that ID does exist and I am allowed to see it, which I can confirm by making the correct kind of request with SoapUI.
Using SoapClient is non-WSDL mode...
$soapClient = new SoapClient(null, array(
"location" => "http://xxx/confluence/rpc/soap-axis/confluenceservice-v1",
"uri" => "http://soap.rpc.confluence.atlassian.com",
"trace" => TRUE));
$token = $soapClient->login(CONFLUENCE_USERNAME, CONFLUENCE_PASSWORD);
$page = $soapClient->getPage($token, $confluence_article_id);
...produces a request for the two-parameter method with incorrect type for the second parameter. When $confluence_article_id is string, the request is...
<SOAP-ENV:Body><ns1:getPage><param0 xsi:type="xsd:string">8Or94ZLqe7</param0><param1 xsi:type="xsd:string">24445207</param1></ns1:getPage></SOAP-ENV:Body>
...which returns the same fault as above:
<faultstring>com.atlassian.confluence.rpc.RemoteException: You're not allowed to view that page, or it does not exist.</faultstring>
When $confluence_article_id is integer, the request is...
<SOAP-ENV:Body><ns1:getPage><param0 xsi:type="xsd:string">y0kF4z0m9L</param0><param1 xsi:type="xsd:int">24445207</param1></ns1:getPage></SOAP-ENV:Body>
...which returns a different kind of fault:
<faultstring>org.xml.sax.SAXException: Bad types (int -> class java.lang.String)</faultstring>
If I take the request, change int to long and try it with SoapUI, it works just fine.
I have also tried to call it using __soapCall, but the results are similar:
$page = $soapClient -> __soapCall('getPage', array('in0'=>$token,'in1'=>$confluence_article_id));
There is a related PHP bug report and another one, and discussion on Atlassian forums, but none of them helped me.
So far the best suggestion has been to tweak the WSDL by removing the other getPage definition and saving it locally somewhere.
If I remember correctly you can call the function using an associative array instead ex:
//Page getPage(String token, String spaceKey, String pageTitle)
$soapClient->getPage(array("token" => $token,"spaceKey" => $spaceKey,"pageTitle" => $pageTitle));
Not tested, standard warnings apply