Results 1 to 7 of 7

Thread: nusoap vs. soap: which to use and why?

  1. #1
    hanmari is offline Sugar Community Member
    Join Date
    Apr 2008
    Posts
    11

    Lightbulb nusoap vs. soap: which to use and why?

    Hello,

    I am integrating SugarCRM Community Edition into an existing backoffice system and am figuring out the basics of how to remotely call SugarCRM's Web Services through Simple Object Access Protocols (SOAP). It seems that SugarCRM places a soap.php file in its root directory, creates a set of soap files in a soap directory, and includes yet another set of soap classes in the include/nusoap directory. Which of these should I use, and why are they setup in this fashion?

    My first instinct is to depend on the soap.php file that is in the root of the SugarCRM project. Indeed, this file seems to be designed as a starting place for all soap interaction, as it does not restrict access through the 'sugarEntry' variable. It also references many other ancillary files, including some in the soap directory and the nusoap.php file in the include/nusoap directory. However, I find that externally referencing the soap.php file in the root of the SugarCRM project results in a series of errors. The $sugar_config variable is overwritten then loses scope, and the SugarBean constructor throws errors when trying to build objects that don't have any parameters. If this soap.php file is designed to encompass all the soap functionality, it seems buggy at best.

    After messing with the soap.php file for some time, I turned to this forum to find hints on how to get soap interactivity to work. Most of the instructions I have found indicate that I should ignore the soap.php file in the root of the project and directly access the nusoap.php file in the include/nusoap directory instead. In order to get the nusoap class to work, I first need to override the security check at the top of the file by setting sugarEntry to true. I can then access the nusoap.php file and its helper classes. I have had some success with following this approach, but wonder if this is the correct/preferred way to access SugarCRM's web services.

    I would appreciate it if someone could clarify SugarCRM's web service design and point me in the right direction so I incorporate SugarCRM's web services using best practices.

    Sincerely,
    Dan

  2. #2
    eggsurplus's Avatar
    eggsurplus is offline Sugar Community Member
    Join Date
    Dec 2005
    Location
    Minnesota
    Posts
    2,858

    Default Re: nusoap vs. soap: which to use and why?

    The soap.php in the root is the file to connect to through SOAP. So your http url would be something like http://mydomain/crm/soap.php

  3. #3
    JVWay is offline Sugar Community Member
    Join Date
    Sep 2007
    Location
    Corvallis, Oregon
    Posts
    452

    Default Re: nusoap vs. soap: which to use and why?

    Start here: http://developers.sugarcrm.com/quickstart.php
    There are examples of the SOAP interface and a lot of other info. Also in your sugar files look at /sugar/examples.

    There are a bunch of files that demonstrate utilization of SOAP.

    One thing I think you're confusing is the WSDL file with the soap implementation which is nusoap. The soap.php is the WSDL file that defines the API whereas the nusoap is the actual implementation that you require_once in your code.

    JW
    Jerry Way
    Business Process Administrator

    Sugar 6.1.4 Professional
    (Testing 6.1.2)
    LAMP on Centos 5
    PHP 5
    MySQL 5
    Apache 2.2

  4. #4
    hanmari is offline Sugar Community Member
    Join Date
    Apr 2008
    Posts
    11

    Lightbulb Re: nusoap vs. soap: which to use and why?

    Thanks for the feedback, guys. I was trying to implement soap.php as a the transport object, when it only carries the web service definitions. I need to instantiate the nusoap class as my transport object with the soap.php file as its set of definitions. Here is the code I got working:

    PHP Code:
    function GetSugarSessionId($myUsername,$myPassword){
        
    // create SOAP object; connect to SOAP.PHP definitions through NUSOAP protocol
        
    if(!defined('sugarEntry'))define('sugarEntry'true); // bypass entryPoint restrictions on NUSOAP
        
    require_once(SUGAR_PATH.'include/nusoap/nusoap.php'); // re-use the NUSOAP class from the remote side
        
    $soapclient = new nusoapclient(SUGAR_URL.'soap.php'); // create a NUSOAP object that uses the soap.php definitions
        
        // setup parameters to send to function through the SOAP object
        
    $config = array();
        
    $config['login'] = array();
        
    $config['login']['user_name'] = $myUsername;
        
    $config['login']['password'] = md5($myPassword);
        
    $config['application_name'] = 'test';
        
        
    // login through the SOAP object
        
    $result $soapclient->call('login',$config);
        
    $session_id $result['id'];
        
        
    // run seamless_login function
        
    $result $soapclient->call('seamless_login',$session_id);
        echo(
    "<a href='".SUGAR_URL."/?MSID=".$session_id."'>click here to login</a>");


  5. #5
    hanmari is offline Sugar Community Member
    Join Date
    Apr 2008
    Posts
    11

    Lightbulb nusoap vs. php soap: which to use and why?

    I decided that PHP's SOAP class is a better transport object than NuSOAP's class. Here is the same code as above, except using PHP's SOAP object instead of NuSOAP's object.

    PHP Code:
    function GetSugarSessionId($myUsername,$myPassword){
        
    $soapclient = new SoapClient(SUGAR_URL.'soap.php?wsdl'); // create a PHP SOAP object that uses SUGAR WSDL definitions in remote soap.php file
        
        // setup parameters to send to function through the SOAP object
        
    $user_auth = array( 
            
    'user_name' => $myUsername
            
    'password' => md5($myPassword),
            
    'version' => $soapclient->get_server_version()
        );
        
    $application "the name of the application you are logging in from. (Currently unused).";

        
    // call SUGAR WSDL login function as method of PHP SOAP object
        
    $result $soapclient->login($user_auth,$application);
        
    $session_id $result->id;
        
        
    // call SUGAR WSDL seamless_login function as method of PHP SOAP object (validates that the session is authenticated)
        
    $result $soapclient->seamless_login($session_id);
        if(
    $result){
            
    // return session_id and direct to remote host with session_id as a parameter
            
    return $session_id;
        }
        else{
            
    // session validation failed
            
    error_log("SESSION IS INVALID: ".$result);
            return 
    false;
        }


  6. #6
    eggsurplus's Avatar
    eggsurplus is offline Sugar Community Member
    Join Date
    Dec 2005
    Location
    Minnesota
    Posts
    2,858

    Default Re: nusoap vs. soap: which to use and why?

    Were you actually able to getting it working in wsdl mode using the building in php_soap library? I had to not use ?wsdl at the end of the url and turn off wsdl to get it to work using php_soap.

  7. #7
    hanmari is offline Sugar Community Member
    Join Date
    Apr 2008
    Posts
    11

    Default Re: nusoap vs. soap: which to use and why?

    Hi eggsurplus,

    Yes, the functions work when I attach the "?wsdl" string to the soap.php URL. I am able to get a session_id when I call the login function and the seamless_login function returns a 1 to show that the session_id I received is valid. When I remove the "?wsdl" parameter from the URL I receive this error: "Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from '<SUGAR_URL>soap.php'". It seems that the $_GET variable "wsdl" needs to be declared in the URL for the SOAP API to work. Perhaps this behavior is PHP version specific. I am using PHP Version 5.2.5-pl1-gentoo and have '--enable-soap' configured.

    The only problem I'm having still is that after I receive the session_id from the SOAP call, I cannot seem to skip past the login screen automatically. Nonetheless, I am definitely receiving responses from my SOAP calls when I attach "?wsdl" to the remote URL for the soap.php file.

    -Dan

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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
  •