I am using php soap. I can't get my soap body to include a custom namespace.
Here is an example of what I want:
<?xml version='1.0' encoding='UTF8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<tns:MyCall xmlns:tns="my.sx"><tns:op>getStuff</tns:op><tns:args />
</tns:MyCall>
</soapenv:Body>
</soapenv:Envelope>
I can't get the namespace called tns to appear inside the body, or the elements op and args.
Can anyone suggest how this is done?
My code looks like:
$client = CreateSoapClient();
try{
$result = $client->__soapCall(
'MyCall',
array(), // no params
array(
'uri' => 'urn:Myurn',
'soapaction' => 'urn:Myurn'
));
?>
You need to define your namespace in your WSDL. It's probably easiest to just use the Zend WSDL autogenerator, which I believe will let you set the namespace. Let me know if you need more information.
Related
I want to learn how to make a SOAP request and then post response in PHP. Here is my request code: http://pastebin.com/PBb2i0XN
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://www.restfulwebservices.net/ServiceContracts/2008/01">
<SOAP-ENV:Body>
<ns1:GetStockQuote>
<ns1:request>Goog</ns1:request>
</ns1:GetStockQuote>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
WSDL is http://www.restfulwebservices.net/wcf/StockQuoteService.svc?wsdl
PHP has a wrapper for SOAP. Check out http://php.net/soap. This should solve all your problems.
You first instantiate a SoapClient class using the following syntax.
$client = new SoapClient("some.wsdl");
You can then use the SoapClient::__getFunctions() method to determine the different functions your WSDL gives you.
public array SoapClient::__getFunctions ( void )
This client will enable you to call the soap functions from your WSDL as if they were PHP functions
For example in order to call the GetStockQuote method from your WSDL, all you have to do is the following.
$client = new SoapClient("http://www.restfulwebservices.net/wcf/StockQuoteService.svc?wsdl");
$client->GetStockQuote();
Also when you use the getFunctions method, you will get a list of all parameters each method in the WSDL expects.
Hope this was helpful. All the best.
How to change my Soapenv:Envelope parameter from this:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ejb="http://ejb.gateway.ebpp.fawryis.com/"
xmlns:ns3678="http://tempuri.org">
to this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ejb="http://ejb.gateway.ebpp.fawryis.com/">
How to set the nusoap client Soapenv so it can be the same as the second format?
Also in every element there is xmlns empty attribute:
<process xmlns="http://ejb.gateway.ebpp.fawryis.com/">
<arg0 xmlns=""><Request xmlns="">
How to remove those xmlns attributes?
Here is my code:
$client = new nusoap_client($wsdl_path, TRUE);
$client->namespaces = array(
'SOAP-ENV'=>"http://schemas.xmlsoap.org/soap/envelope/",
'ejb'=>"http://ejb.gateway.ebpp.fawryis.com/"
);
$parameters = array(//the parameters );
$result = $client->call("process", $parameters);
Thank you
I understand you could fork Nusoap project and customize nusoap.php source code to return exactly what you whish. But notice that some people are telling us we don't need to bother with this prefix SOAP-ENV. If you do not care about which one is being serialized (SOAP-ENV or soap prefix), keep using the original nusoap project. Remember to enter the same namespace.
Here some extra information:
You can use any string you like as a namespace prefix, just as long as
it maps to the appropriate namespace name. The reason why the spec
bothers with telling us the notational conventions is that prefix
names (e.g., SOAP-ENV) aren't normative.
Source: SOAP-ENV vs. soapenv
...as long as soap and SOAP-ENV refer to the same namespace URI, then
everything will be OK.
Source: SOAP-ENV: vs. soap:Envelope
...can be any allowed string - it does not matter to the XML parser as
long as the correct namespace URL has been given.
Source: SOAP Envelope namespace
I'm trying to connect to a WSDL webservice using PHP SOAP. Now I need to remove the SOAP elements from the XML which is send. What I have now is the following:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://service.com">
<SOAP-ENV:Body>
<ns1:Calculate>
//Content
</ns1:Calculate>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
What I want is the following:
<?xml version="1.0" encoding="UTF-8"?>
<ns1:Calculate xmlns:ns1="http://service.com">
//Content
</ns1:Calculate>
Is there any way to accomplish this? Is SOAP the one I need to send such requests?
SOAP is protocol, and if you want to SOAP request both client and server side must accept and send back requests according to this protocol.
Just check these settings :
$client = new SoapClient("some.wsdl", array('soap_version' => SOAP_1_2));
Server may uses 1_2 or 1_1 version.
And you should contact with Web Service provider to get documentation about implementation of web service.
Override SoapClient class with a customized __doRequest. The new method removes the namespace references from the XML then calls the parent's __doRequest to fulfill the request with the modified XML. A simple but effective solution.
class MySoapClient extends SoapClient
{
public function __doRequest($request, $location, $action, $version, $one_way=0)
{
$request = str_replace('ns1:', '', $request);
parent::__doRequest($request, $location, $action, $version, $one_way);
}
}
# Invoke derived class instead of base class SoapClient
$client = new MySoapClient($wsdl, $options);
If you want to make a SOAP request, these tags are required. Is it really SOAP server on your opposite trying to make request?
I previously managed to call a .NET service using PHP's SoapClient library without too many issues, but now I face a scenario where I have to access the same services in non-WSDL mode.
I seem to have created, more or less, the correct XML structure to send through to the service, but the server does not seem to be picking up the variables I am sending.
Based on output from SOAPUI, I should be attempting to generate the following SOAP call:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:int="http://someservices.com/">
<soapenv:Header/>
<soapenv:Body>
<int:getService>
<int:foo>String value for foo</int:foo>
<int:bar>String value for bar</int:bar>
</int:getService>
</soapenv:Body>
</soapenv:Envelope>
The output that I am generating with SOAPClient is:
<?xml version="1.0" encoding="UTF-8"?> <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://someservices.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:enc="http://www.w3.org/2003/05/soap-encoding">
<env:Body>
<ns1:getService env:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<foo xsi:type="xsd:string">String value for foo</foo>
<bar xsi:type="xsd:string">String value for bar</bar>
</ns1:getService>
</env:Body>
</env:Envelope>
The error returned from the .NET service is "bar expected!" - indicating, at the very least, that the service is not picking up my second parameter.
I am constructing my soap call using the following:
$foo = 'String value for foo';
$bar = 'String value for bar';
$options = array(
'trace' => 1,
'exceptions' => 1,
'uri' => 'http://someservices.com',
'soapaction' => 'http://someservices.com/getService',
'soap_version' => SOAP_1_2,
'type_map' => array('type_ns' => 'int')
);
$response = $soapclient->__soapCall('getService', array( new SoapParam($foo, 'foo'), new SoapParam($bar, 'bar')), $options);
I am not sure what the issue is. Right now I am guessing that it might be an xmlns attribute issue. Note that the SOAPUI call specifies the int: in front of the function calls and parameters. I have tried to specify this xmlns but without luck. As you can see xmlns generated by Soap Client call is:
xmlns:ns1
Any help would be greatly appreciated.
As it turns out, having the namespace labelled as ns1 instead of int was not the issue.
The problem was that the getService parameter was being prefixed with the namespace ns1, whilst the variables foo and bar were not.
As such, this was resolved by appending "ns1:" to the Soap Params in the soapCall function, as follows:
$response = $soapclient->__soapCall('getService', array( new SoapParam($foo, 'ns1:foo'), new SoapParam($bar, 'ns1:bar')), $options);
I don't know PHP, just the basics (if so...).
I have a method in my web service like this:
$server->register(
'registerDeviceOnServer', //method name
array('uniqueIdentifier' => 'xsd:string','deviceName' => 'xsd:string', 'systemVersion' => 'xsd:string', 'deviceModel' => 'xsd:string', 'userLocation_Locality' => 'xsd:string', 'userLocation_CountryCode' => 'xsd:string' ), //input data
array('xmlReturn' => 'xsd:string'), //output data
'urn:server.AAAA', //namespace
'urn:server.AAAA#registerDeviceOnServer', //soapaction
'rpc', //style
'encoded', //use
'regista o iDevice' //info for documentation
);
function registerDeviceOnServer($uniqueIdentifier,$deviceName,$systemVersion,$deviceModel,$userLocation_Locality,$userLocation_CountryCode)
{
//some code that talks to the database
//inserting the data into a table
//
//the SQL code works fine. I've tested.
}
When I call the web service, the data does not come in that exact order as it is declared in the php method. Does it have to come in that order, or does PHP assign the data to the vars?
SOAP request:
<?xml version="1.0" encoding="utf-8"?><soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<registerDeviceOnServer xmlns="urn:server.AAAA">
<uniqueIdentifier>VVVVVVVVVVVVWWWWWWWW</uniqueIdentifier>
<userLocation_CountryCode>n/a</userLocation_CountryCode><deviceModel>iPhone Simulator</deviceModel><systemVersion>4.0</systemVersion><deviceName>iPhone OS</deviceName><userLocation_Locality>n/a</userLocation_Locality>
</registerDeviceOnServer>
</soap:Body>
</soap:Envelope>
So, how can I work this out?
Thanks,
RL
From your comments I can now see that you are actually using nusoap.php and not PHP's own SoapServer.
Check this forum post:
I had a similar issue recently which was caused because I didn't
provide a WSDL url to my SoapServer constructor.
Apparently the soap server can only map message arguments / parameters
when it has a valid WSDL for reference (which more or less made sense
to me afterwards).
Does this help you?
As #akirk says, maybe your problem is related to the WSDL. Make sure that the parameters are in the same order that's in the WSDL