How to submit a SOAP request to wsdl

Hi Guys,

I am not very familiar with SOAP, so I have an xml that i need to submit it to a wsdl and I now the format and methods the xml needs, but i just struggle/dont know how to submit it using SAOP.

here is what I have so far:


$client = new
    SoapClient(
        "http//:www.url.com?wsdl"
    );


try {
    echo "<pre>\
";
    print($client->submitNewSurveyResponse());
    echo "\
";
  } catch (SoapFault $exception) {
    echo $exception;      
  } 

and the xml format is here:


URL:
===================================
http//:www.url.com?wsdl

Method:
===================================
submitNewSurveyResponse 

Returns:
===================================
On Failure: -1
On Success: iMarketing Sync ID

Parameters:
===================================
accesskey (string): 1ysr3w7gr57fqz2qr8nl 

response (string):
<?xml version="1.0" encoding="UTF-16"?>
<iMAWebServiceRequests>
	<Requests>
		<SurveyResponse surveyID="42261" leadsource="" clicksource="" iMarketingSyncID=""  mode="live">
			<Response questionID="1">
				<DisplayText><![CDATA[First Name]]></DisplayText>
				<UserInput><![CDATA[]]></UserInput>
			</Response>
			<Response questionID="2">
				<DisplayText><![CDATA[Last Name]]></DisplayText>
				<UserInput><![CDATA[]]></UserInput>
			</Response>
			<Response questionID="14">
				<DisplayText><![CDATA[Email Address]]></DisplayText>
				<UserInput><![CDATA[]]></UserInput>
			</Response>
			<Response questionID="105330">
				<DisplayText><![CDATA[What is your SEX?]]></DisplayText>
				<UserInput><![CDATA[]]></UserInput>
			</Response>
			<Response questionID="106763">
				<DisplayText><![CDATA[checkbox]]></DisplayText>
				<UserInput><![CDATA[]]></UserInput>
			</Response>
			<Response questionID="108819">
				<DisplayText><![CDATA[Age]]></DisplayText>
				<UserInput><![CDATA[]]></UserInput>
			</Response>
		</SurveyResponse>
	</Requests>
</iMAWebServiceRequests>

It’s been a long time since I’ve used this so I can’t really explain the details, but maybe this code will help. It retrieved forecast data from the national weather service.

function getForecastXML($lat,$lon)
{
	$soapclient = new soapclient('http://www.weather.gov/forecasts/xml/SOAP_server/ndfdXMLserver.php?wsdl',true);
	
	$err = $soapclient->getError();
	if ($err) {
	  //error was handled here
	}
	
	$parameters = array('latitude' => $lat,
		'longitude' => $lon,
		'product' => "time-series",
		'startTime' => date("Y-m-d",time())."T00:00",
		'endtime' => "",
		'weatherParameters' => array(
		'maxt' => TRUE,
		'mint' => TRUE,
		'temp' => TRUE,
		'dew' => TRUE,
		'pop12' => TRUE,
		'qpf' => FALSE,
		'sky' => TRUE,
		'snow' => FALSE,
		'wspd' => TRUE,
		'wdir' => TRUE,
		'wx' => TRUE,
		'waveh' => FALSE,
		'icons' => FALSE,
		'rh' => TRUE,
		'appt' => TRUE,
		'incw34' => FALSE,
		'incw50' => FALSE,
		'incw64' => FALSE,
		'cumw34' => FALSE,
		'cumw50' => FALSE,
		'cumw64' => FALSE,
		'conhazo'=> FALSE,
		'ptornado' => FALSE,
		'phail'	=> FALSE,
		'ptstmwinds' => FALSE,
		'pxtornado' => FALSE,
		'pxhail' => FALSE,
		'pxtstmwinds' => FALSE,
		'ptotsvrtstm' => FALSE,
		'pxtotsvrtstm' => FALSE,
		'wgust' => FALSE,
		));
	
	$result = $soapclient->call('NDFDgen',$parameters,
		'uri:DWMLgen',
		'uri:DWMLgen/NDFDgen');
	return $result;
}

hey smallshot thanks for this, i’ll give it try.

If anyone has done this before please let us know.

thanks

This comment might help a little too:
http://www.php.net/manual/en/soapclient.soapcall.php#57032

thanks for the link smallshot. I’ve hit the wall on this, I need to know how I send a request to wsdl based on the the xml format below:


URL:
===================================
http://www.url/com?wsdl 

Method:
===================================
submitNewSurveyResponse 

Returns:
===================================
On Failure: -1
On Success: iMarketing Sync ID

Parameters:
===================================
accesskey (string): 1ysr3w7gr57fqz2qr8nl 

response (string):
<?xml version="1.0" encoding="UTF-16"?>
<iMAWebServiceRequests>
	<Requests>
		<SurveyResponse surveyID="42261" leadsource="" clicksource="" iMarketingSyncID=""  mode="live">
			<Response questionID="1">
				<DisplayText><![CDATA[First Name]]></DisplayText>
				<UserInput><![CDATA[]]></UserInput>
			</Response>
			<Response questionID="2">
				<DisplayText><![CDATA[Last Name]]></DisplayText>
				<UserInput><![CDATA[]]></UserInput>
			</Response>
			<Response questionID="14">
				<DisplayText><![CDATA[Email Address]]></DisplayText>
				<UserInput><![CDATA[]]></UserInput>
			</Response>
			<Response questionID="105330">
				<DisplayText><![CDATA[What is your SEX?]]></DisplayText>
				<UserInput><![CDATA[]]></UserInput>
			</Response>
			<Response questionID="106763">
				<DisplayText><![CDATA[checkbox]]></DisplayText>
				<UserInput><![CDATA[]]></UserInput>
			</Response>
			<Response questionID="108819">
				<DisplayText><![CDATA[Age]]></DisplayText>
				<UserInput><![CDATA[]]></UserInput>
			</Response>
		</SurveyResponse>
	</Requests>
</iMAWebServiceRequests>

Anyone plz plz??

bump…

Let me get this straight, you want to call a soap function called submitNewSurveyResponse, and you need to pass it 2 parameters, the access key and the response XML, right?

If I got that right, then you first need to get your xml into a string variable, call it $responseXML, and your access key into another variable called $accessKey, then you can use this code:

$client = new SoapClient("http//:www.url.com?wsdl");
$parameters = array('accessKey'=>$accessKey, 'response'=>$responseXML);
try {
    echo "<pre>\
";
    print($client->__soapCall('submitNewSurveyResponse', $parameters);
    echo "\
";
  } catch (SoapFault $exception) {
    echo $exception;      
  }

That SHOULD work.

hey smallshot when you say string do you mean this:


$responseXML="<xml code>";

or actually load it using simplexmnl like so:


$xmlstr = file_get_contents('xml_file.xml');
$responseXML = new SimpleXMLElement($xmlstr);

if you use simplexml, you need to call asXML() to convert it to a string before sending it through soap. your first example is fine, or in your second example, $xmlstr is already in the format you need for soap.

smallshot thank very much man…wooo…spent so much time trying to figuer out how to sent these params…but thanks for the help.

here is the complete code in case it helps anyone else:


<?php
$responseXML='<?xml version="1.0" encoding="UTF-16"?>

<iMAWebServiceRequests>

	<Requests>

		<SurveyResponse surveyID="42261" leadsource="" clicksource="" iMarketingSyncID=""  mode="live">

			<Response questionID="1">

				<DisplayText><![CDATA[First Name]]>amanda</DisplayText>

				<UserInput><![CDATA[]]></UserInput>

			</Response>

			<Response questionID="2">

				<DisplayText><![CDATA[Last Name]]>amanda</DisplayText>

				<UserInput><![CDATA[]]></UserInput>

			</Response>

			<Response questionID="14">

				<DisplayText><![CDATA[Email Address]]></DisplayText>

				<UserInput><![CDATA[zdsfsf@hshsdh.com]]></UserInput>

			</Response>

			<Response questionID="105330">

				<DisplayText><![CDATA[What is your SEX?]]></DisplayText>

				<UserInput><![CDATA[Male]]></UserInput>

			</Response>

			<Response questionID="106763">

				<DisplayText><![CDATA[checkbox]]></DisplayText>

				<UserInput><![CDATA[male]]></UserInput>

			</Response>

			<Response questionID="108819">

				<DisplayText><![CDATA[Age]]></DisplayText>

				<UserInput><![CDATA[25]]></UserInput>

			</Response>

		</SurveyResponse>

	</Requests>

</iMAWebServiceRequests>';
$accessKey="1ysr3w7gdfdfr57fqz2qr8nl";

$client = new SoapClient("http://www.url.com?wsdl");
$parameters = array('accessKey'=>$accessKey, 'response'=>$responseXML);
try {
    echo "<pre>\
";
    print($client->__soapCall('submitNewSurveyResponse', $parameters));
    echo "\
";
  } catch (SoapFault $exception) {
    echo $exception;      
  } 

?>

although another question, how else would I have been able to submit the params. in this case per your advise i had to load the xml as a string and for each xml element i had to declare the attribute the xml element and value in the cdata like this:
<Response questionID=“108819”>
<DisplayText><![CDATA[Age]]></DisplayText>
<UserInput><![CDATA[25]]></UserInput>
</Response>

notice Age and the 25, could i not have done through an array like so $array=array(‘Age’=>‘25’, etc)?

It seems like it has to be in XML for that particular soap function to work. I don’t think you have to wrap everything in the CDATA tags unless you are going to be inserting free text that could contain XML symbols like < >, but maybe they require it since it is in the example.

this may also work:
<Response questionID=“108819”>
<DisplayText>Age</DisplayText>
<UserInput>25</UserInput>
</Response>