PHP SoapClient creating error: "Namespace must not match the enclosing schema" - php

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

Related

WSDL-SOAP Webservice on PHP

I have created php file. It contains details about to access (wsdl)xml file and function. I need to call a function with paramaters but i can't able to call a function. So, I have been given a WSDL file and I need to create a SOAP service for it in PHP. Could any one tell me what the correct way of doing it is?
Here is link of the WSDL: http://178.211.55.56/se/ws/wf_ws.php?wsdl
and
Here is my php code:
require_once 'lib/nusoap.php';
ini_set("soap.wsdl_cache_enabled", "0");
$soapclient = new nusoap_client("http://178.211.55.56/se/ws/wf_ws.php?wsdl",'wsdl');
$soapclient->setHTTPProxy("soap:address_location",8080,"usr_name","pwd");
when run above the php code return this error:
wsdl error: Getting "WSDL link" - HTTP ERROR: Couldn't open socket
connection to server "WSDL link" prior to connect(). This is often a
problem looking up the host name.
Try to use http://php.net/manual/en/class.soapclient.php
All you need is:
Create SOAP client:
$client = new SoapClient("http://178.211.55.56/se/ws/wf_ws.php?wsdl");
You can pass many options to the constructor, such as proxy, cache settings, etc.
Some examples for you:
$client = new SoapClient("some.wsdl", array('soap_version' => SOAP_1_2));
$client = new SoapClient("some.wsdl", ['login' => "some_name", 'password'=> "some_password"]);
$client = new SoapClient("some.wsdl", ['proxy_host' => "localhost", 'proxy_port' => 8080]);
If ssl certificate is wrong you can ignore it. Example is here: https://gist.github.com/akalongman/56484900eaf19b18cfbd
Call one of the service defined functions:
$result = $client->getResult(['param_name' => 'param_value']);
Pay attention that your service function may have required parameters. Usually it can be found in the result message.

Execute a SoapClient __soapCall without WSDL page

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

How do I call SOAP methods in PHP using namespaces (in params and methods) and nested structures (in params)?

Assume I have this XML (it is a SOAP call)
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ext="http://api.movilway.net/schema/extended">
<soapenv:Header/>
<soapenv:Body>
<ext:GetBalanceRequest>
<ext:AuthenticationData>
<ext:Username>Foo</ext:Username>
<ext:Password>Bar$123!password</ext:Password>
<ext:SessionID>as3hy4ri37g2f345</ext:SessionID>
</ext:AuthenticationData>
<ext:DeviceType>3</ext:DeviceType>
</ext:GetBalanceRequest>
</soapenv:Body>
</soapenv:Envelope>
(Foo, Bar$123!password, as3hy4ri37g2f345 and 3 are just sample values)
Usually, when I want to do simple SOAP calls, I use a SoapClient like this:
$sc = new SoapClient('http://my.url/my/service?wsdl');
$result = $sc->someMethod(array('some' => 'params'));
But this one seems to use xsd namespaces and nested structures.
Q: How do I call methods with namespaces prefixes (ext:, in this case) AND parameters with namespaces prefixes (and nested structures)?
Edit: What I tried involves including the namespace as the uri option. And got an exception like this:
SoapFault : Function ("GetBalanceRequest") is not a valid method for this service
The code I tried was this:
try {
$client = new SoapClient('http://THEURLHERE/Path/To/The/Service?wsdl', array('uri' => 'http://api.movilway.net/schema/extended'));
print_r($client->GetBalanceRequest(
array(
'AuthenticationData' => array(
'Username' => 'MYUSERHERE',
'Password' => 'MYPASSWORDHERE'
),
'DeviceType' => 1
)
));
} catch(Exception $e) {
print_r($e);
}
Assume there's no error nor typo since I got the required XML directly from the documentation.
Q+: What must I add to the code to send such request?
Firstly, the correct term is not "extension", but "namespace" - it's just coincidence that the namespace here is called "extended" and has been given the alias ext: in the example.
Secondly, an XML namespace is simply a way of saying "these elements and attributes are of a particular type"; it does not automatically imply any special structure beyond normal XML - it has no automatic relationship to an XSD, for instance. A namespace is uniquely identified by a URI, which needn't actually point anywhere (see this previous answer for more on that). Within a document, it is given an arbitrary prefix, so that you don't have to write the URI next to every element.
SOAP itself uses the namespace http://schemas.xmlsoap.org/soap/envelope/ for the elements that represent the SOAP "envelope", here given the alias soapenv. The "body" of the SOAP message is not in that namespace, so it is common for SOAP services to declare their elements as part of some other specific namespace; if they didn't, they would be in the default, nameless, namespace.
So, so much for theory. On to practice:
If you are using a WSDL to load the web service, and that WSDL is properly formed, the SOAPClient class should add the appropriate namespace to your request automatically. Since the request exists entirely inside that namespace, there is no need to distinguish between "AuthenticationData in namespace http://api.movilway.net/schema/extended" and just "AuthenticationData".
If this doesn't work for some reason, or you have no WSDL, you may need to create SoapVar objects with the appropriate namespace assigned to them.
However, based on the error message you just edited into your question, all of the above may be completely irrelevant, because the problem might have nothing to do with namespaces at all - you are operating in WSDL mode, and the client is telling you that the method doesn't exist. So, the obvious question to me is, is that method definitely defined in that WSDL file?

PHP error when try execute .net webservice method

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

How to call overloaded SOAP method with PHP SoapClient?

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

Categories