I am trying to build a web service to a specification of a 3rd party who will be connecting to it as a client, the service must be written in PHP but I am a total PHP n00b so struggling a little. Basically my responses are being wrapped in a element however the client is not accepting my responses because of this, here is an example.
service.php
<?php
class MyService {
public function Ping() {
return date('d/m/Y H:i:s');
}
}
$server = new SoapServer(null, array( 'soap_version' => SOAP_1_2, 'encoding' => 'UTF-8', 'uri' => 'http://tempuri.org/'));
$server->setClass("MyService");
$server->handle();
?>
Request
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:Ping />
</soapenv:Body>
</soapenv:Envelope>
Response
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:PingResponse>
<return xsi:type="xsd:string">18/11/2010 18:51:02</return>
</ns1:PingResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
What the client is expecting is the PingResponse to just contain the date but without the wrapped around the outside. How can I get the PHP SoapClient to do this?
E.g.
<ns1:PingResponse>18/11/2010 18:51:02</ns1:PingResponse>
I don't think you can, I think this is written into the core of SOAP so it's something your client will have to work around. If they're already getting the contents of PingResponse I can't see it being much more difficult for them to go 1 tree deeper into the response.
Related
I need to debug a soap webservice but i don't know where to start.
This is returning wrong data and i need to find why.
It is running on http://localhost:18385 and i can control the parameters that i send but don't know the endpoint file .
if i write http://localhost:18385 on browser i get
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:IDSP="http://ns.adobe.com/InDesign/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring>HTTP GET method not implemented</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Thanks in advance
The easiest way to debug is to use an app like Postman or SoapUI, so you can set up what you post and see the response in detail.
You are getting an error because you are using GET in your script, InDesign Server expects POST request with Content-Type of xml/text and Body set to the Soap call, e.g.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://ns.adobe.com/InDesign/soap/">
<soapenv:Body>
<soap:RunScript>
<runScriptParameters>
<scriptLanguage>javascript</scriptLanguage>
<scriptFile>C:\InDesign\scriptfile.jsx</scriptFile>
<scriptArgs>
<name>myParameter</name>
<value>305</value>
</scriptArgs>
</runScriptParameters>
</soap:RunScript>
</soapenv:Body>
</soapenv:Envelope>
You're not giving much detail of what exactly you need.
If you're asking what's the WSDL path, it should be: http://localhost:18385/service?wsdl
If you need to debug a SOAP web service response you can either create a PHP test script using SoapClient or use SoapUI.
I need this xml in out:
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="https://server/">
<soapenv:Header>
<authenticate>111111111111</authenticate>
<SOAP-ENV:Header/>
My php code is:
$head = new stdClass();
$head->authenticate='1111111111111111';
$header = new SoapHeader('ns1','authenticate',$head,false);
$client = new SoapClient ('https://server',array("trace" => 1, "exceptions" => 1));
$client->__setSoapHeaders($header);
I get this XML:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="https://server"
xmlns:ns2="https://server">
<SOAP-ENV:Header>
<ns2:authenticate>
<authenticate><BOGUS>anc401t9n4dknmgp2bv629ori7</BOGUS>
</authenticate></ns2:authenticate>
</SOAP-ENV:Header
><SOAP-ENV:Body>...
How can I get needed xml? Can fully rewrite soapheader with php client SoapClient? Or how I can adding one string whithout creating new namespace?
If your Web Service is well documented within its WSDL, try using wsdltophp.com or PackageGenerator as it generates the methods to properly set the SoapHeader very easily and so for the whole request.
I am trying to consume a .NET SOAP service but I'm currently just getting a 'false' response.
Visiting the service endpoint tells me the following:
The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values.
<?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>
<SendData xmlns="http://tempuri.org/">
<myObj>string</myObj>
</SendData>
</soap:Body>
</soap:Envelope>
But when I check my request, it is sending the following:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/">
<SOAP-ENV:Body>
<ns1:SendData>
<ns1:myObj>My data</ns1:myObj>
</ns1:SendData>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
So we can see that my request has different nodes titles and also adds in "ns1:" to the parameters.
Here is my (brief) PHP
$soap = new SoapClient('wsdl.xml', array("trace" => 1, "exception" => 1));
$call = $soap->__soapCall("SendData", array("SendData" => array("myObj" => "My data")));
So my question is: Could this difference in request schema be responsible for the request failing or is this just another way of writing the same thing? If it is responsible, is it possible to write my request exactly as specified at the endpoint?
It is the same thing.
In the given example <SendData xmlns="http://tempuri.org/"> is without namespace prefix (the ns1 in your own request) so default prefix is used, and it specifies it with xmlns attribute for itself and its descendants.
In your request ns1 namespace prefix is defined using xmlns:ns1="http://tempuri.org/" and used in <ns1:SendData>.
I'm stuck developing in an environment where I cannot use the PHP DFP library. I'm using PHP's SoapClient and I'm having trouble forming the headers correctly for SOAP requests. Here's the example:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<ns1:RequestHeader
soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next"
soapenv:mustUnderstand="0"
xmlns:ns1="https://www.google.com/apis/ads/publisher/v201308">
<ns1:authentication xsi:type="ns1:ClientLogin" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ns1:token>SuchALongToken</ns1:token>
</ns1:authentication>
<ns1:networkCode>123456</ns1:networkCode>
<ns1:applicationName>DfpApi-Java-2.1.0-dfp_test</ns1:applicationName>
</ns1:RequestHeader>
</soapenv:Header>
<soapenv:Body>
<getAdUnitsByStatement xmlns="https://www.google.com/apis/ads/publisher/v201308">
<filterStatement>
<query>WHERE parentId IS NULL LIMIT 500</query>
</filterStatement>
</getAdUnitsByStatement>
</soapenv:Body>
</soapenv:Envelope>
It's the Authentication section that's getting me. Not sure how to set the internal params (type and xsd) and create the 'token' child.
$header_params = new stdClass();
$header_params->networkCode = self::$network_code;
$header_params->applicationName = $app_name;
$header_params->authentication = array('token' => $this->auth_token);
$headers = new SoapHeader(self::getNamespace(), 'RequestHeader', $header_params);
This gets me the following:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://www.google.com/apis/ads/publisher/v201308">
<SOAP-ENV:Header>
<ns1:RequestHeader>
<ns1:networkCode>########</ns1:networkCode>
<ns1:applicationName>Get Companies By Filter</ns1:applicationName>
<ns1:authentication />
</ns1:RequestHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:getCompaniesByStatement>
<ns1:filterStatement />
</ns1:getCompaniesByStatement>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Looks like wsdl is rejecting my authentication as well as my filterStatement. I'd be happy to get the authentication working at the moment. This request give me an 'Unmarshalling' error.
Any help would be much appreciated!
The format of my SOAP call needs to be:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/">
<SOAP-ENV:Body>
<ns1:FunctionName>
<ns1:HostUserName>hostuser</ns1:HostUserName>
<ns1:HostPassword>pass</ns1:HostPassword>
<ns1:OwnerName>owner</ns1:OwnerName>
<ns1:UserName>user</ns1:UserName>
<ns1:OptionalParam>
<ns1:Parameters>
<ns1:Parameter Name="FirstName">First<ns1:/Parameter>
<ns1:Parameter Name="LastName">Last<ns1:/Parameter>
<ns1:/Parameters>
</ns1:OptionalParam>
<ns1:/FunctionName>
</SOAP-ENV:Body>
How do I represent this in a PHP request?
I build the request like this:
$client = new SoapClient($url,array('trace' => 1));
$data['HostUserName']=$this->hostname;
$data['HostPassword']=$this->hostpassword;
$data['OwnerName']=$this->ownername;
$data['UserName']=$username;
$data['FirstName']=$FirstName;
$data['LastName']=$LastName;
$result = $client->FunctionName($data);
I've tried a few combinations of building arrays, SOAPVAR and SOAPPARAM but nothing has worked.
The target SOAP server is .NET based.
Any suggestions?
Thanks