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
Related
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 received a manual to internal SOAP interface of my partner. It says:
MyPARTNER web services are provided in the form of a SOAP interface. The service is available in this URL: https://justsomeurl.com:435/soap
then some bla bla about authorization etc. and then a part about Accessible Methods:
pull()
The PULL method is used for pulling data from the database. The method
receives a unique data based parameter under an internal name
requestXML. This parameter contains data in a structured XML format.
String pull(String requestXML)
The XML contains data required to make the request, and the response
data is sent back.
then some other methods, error codes, it's not important here...
The problem is that I'm totally unexperienced in SOAP so I don't know how to use this interface via PHP. I've tried to find some examples, tutorials and I am now little bit more informed about SOAP and its functionality but still haven't found any advice about how to use interface like this...
thanx for any help
Php comes with PHP SOAP libraries, that usually are included and enabled after a common php installation.
Yuo are asked to biuld the client part of the webservice pattern. Your partner should provide you the .wsdl of the web service. The wsdl describes the avialble method, the parameters they need and what they return.
Tipically parameters and return values are array structures
This could be a skeleton for your code:
//build a client for the service
$client = new SoapClient("partner.wsdl");
//$client is now a sort of object where you can call functions
//prepare the xml parameter
$requestXML = array("parameter" => "<xml>Hello</xml>");
//call the pull function this is like
$result = $client->__soapCall("pull", $requestXML );
//print the value returned by the web service
print_r($result);
Here follows a non-wsdl example
First the location paramater is the address the SOAP request will be sent to.
The uri parameter is the target namespace of the SOAP service. This is related to xml namespaces.
A sample code for you could be:
//for URI specification you should watch your partners documentation. maybe also a fake uri (like mine) could work
//build a client for the service
$client = new SoapClient(null, array(
'location' =>
"https://justsomeurl.com:435/soap",
'uri' => "urn:WebServices",
'trace' => 1 ));
// Once built a non-wsdl web service works as a wsdl one
//$client is now a sort of object where you can call functions
//prepare the xml parameter
$requestXML = array("parameter" => "<xml>Hello</xml>");
//call the pull function this is like
$result = $client->__soapCall("pull", $requestXML );
//print the value returned by the web service
print_r($result);
Here a useful link: http://www.herongyang.com/PHP/SOAP-Use-SOAP-Extension-in-non-WSDL-Mode.html
I'm getting "Namespace must not match the enclosing schema" error when trying to create SoapClient object. Code is simple:
<?php $client = new \SoapClient('http://www.server.com/Service?wsdl');
How can I create object by ignoring this error?
I'm not sure what the WSDL looks like, so it's a bit hard to tell if the error can be avoided. However, you can switch to creating a SoapClient using non WSDL mode:
$client = new SoapClient(null, array('location' => "http://localhost/soap.php",
'uri' => "http://test-uri/"));
Where location and uri are described as:
An array of options. If working in
WSDL mode, this parameter is optional.
If working in non-WSDL mode, the
location and uri options must be set,
where location is the URL to request
and uri is the target namespace of the
SOAP service.
Source: http://www.php.net/manual/en/soapclient.soapclient.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