SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2005
    Location
    London, UK
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:
    PHP Code:
    $client = new
        
    SoapClient(
            
    "http//:www.url.com?wsdl"
        
    );


    try {
        echo 
    "<pre>\n";
        print(
    $client->submitNewSurveyResponse());
        echo 
    "\n";
      } catch (
    SoapFault $exception) {
        echo 
    $exception;      
      } 
    and the xml format is here:
    PHP Code:
    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>

  2. #2
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    PHP Code:
    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;


  3. #3
    SitePoint Evangelist
    Join Date
    Apr 2005
    Location
    London, UK
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey smallshot thanks for this, i'll give it try.

    If anyone has done this before please let us know.

    thanks

  4. #4
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This comment might help a little too:
    http://www.php.net/manual/en/soapcli...call.php#57032

  5. #5
    SitePoint Evangelist
    Join Date
    Apr 2005
    Location
    London, UK
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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:

    PHP Code:
    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??

  6. #6
    SitePoint Evangelist
    Join Date
    Apr 2005
    Location
    London, UK
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    bump...

  7. #7
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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:
    PHP Code:
    $client = new SoapClient("http//:www.url.com?wsdl");
    $parameters = array('accessKey'=>$accessKey'response'=>$responseXML);
    try {
        echo 
    "<pre>\n";
        print(
    $client->__soapCall('submitNewSurveyResponse'$parameters);
        echo 
    "\n";
      } catch (
    SoapFault $exception) {
        echo 
    $exception;      
      } 
    That *SHOULD* work.

  8. #8
    SitePoint Evangelist
    Join Date
    Apr 2005
    Location
    London, UK
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by smallshot View Post
    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:
    PHP Code:
    $client = new SoapClient("http//:www.url.com?wsdl");
    $parameters = array('accessKey'=>$accessKey'response'=>$responseXML);
    try {
        echo 
    "<pre>\n";
        print(
    $client->__soapCall('submitNewSurveyResponse'$parameters);
        echo 
    "\n";
      } catch (
    SoapFault $exception) {
        echo 
    $exception;      
      } 
    That *SHOULD* work.
    hey smallshot when you say string do you mean this:
    PHP Code:
    $responseXML="<xml code>"
    or actually load it using simplexmnl like so:
    PHP Code:
    $xmlstr file_get_contents('xml_file.xml');
    $responseXML = new SimpleXMLElement($xmlstr); 

  9. #9
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  10. #10
    SitePoint Evangelist
    Join Date
    Apr 2005
    Location
    London, UK
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by smallshot View Post
    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 Code:
    <?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>\n";
        print(
    $client->__soapCall('submitNewSurveyResponse'$parameters));
        echo 
    "\n";
      } catch (
    SoapFault $exception) {
        echo 
    $exception;      
      } 

    ?>

  11. #11
    SitePoint Evangelist
    Join Date
    Apr 2005
    Location
    London, UK
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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)?

  12. #12
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •