Consuming .Net WebService with PHP and NuSOAP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amine
    New Member
    • Sep 2006
    • 2

    #1

    Consuming .Net WebService with PHP and NuSOAP

    Hello People,
    I created a WebService in .NET on my machine with following methode:

    Code:
     <WebMethod(Description:="test")> _ 
    Public Function sayHello(ByVal myName As String, ByVal myID As Integer) As String
    Return "Hello " & myName & " (" & myID & ")"
    End Function
    Web service works fine, I can access my function in .NET without problem.
    I can also access the function using PHP and NuSOAP however I CANNOT pass the parameters, so the result of my php page is only:
    "Hello ()"

    hereby is some php code I'm using:
    What am I doing false:

    Code:
     <?php 
     
    /*NuSOAP*/
    require_once('NuSOAP/nusoap.php');
    $proxyhost = isset( $POST['proxyhost']) ? $POST['proxyhost'] : '';
    $proxyport = isset( $POST['proxyport']) ? $POST['proxyport'] : '';
    $proxyusername = isset( $POST['proxyusername']) ? $POST['proxyusername'] : '';
    $proxypassword = isset( $POST['proxypassword']) ? $POST['proxypassword'] : '';
    $client = new soapclient('http://localhost/myWS/myWS.asmx?wsdl', true, $proxyhost, $proxyport, $proxyusername, $proxypassword);
    $err = $client->getError();
    if ($err) {
    echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
    }
    $params = 'amine';
    $result = $client->call("sayHello", $params);
    // Check for a fault
    if ($client->fault) {
    echo '<h2>Fault</h2><pre>';
    print_r($result);
    echo '</pre>';
    } else {
    // Check for errors
    $err = $client->getError();
    if ($err) {
    // Display the error
    echo '<h2>Error</h2><pre>' . $err . '</pre>';
    } else {
    // Display the result
    echo '<h2>Result</h2><pre>';
    print_r($result);
    echo '</pre>';
    }
    }
    ?>
    Last edited by Niheel; Sep 4 '06, 06:37 PM.
  • bmiller264
    New Member
    • Feb 2007
    • 1

    #2
    amine,

    I believe that the problem is in the way you set your parameters, they need to be set as named values and wrapped in an outer "parameters " array for .Net.

    Code:
    $client = new soapclient('http://localhost/myWS/myWS.asmx?wsdl', true, $proxyhost, $proxyport, $proxyusername, $proxypassword);
    $err = $client->getError();
    $params = array('parameters' => array ('name' => 'amine'));
    $result = $client->call("sayHello", $params);
    Last edited by Markus; Nov 28 '08, 11:32 AM. Reason: fixed code tags

    Comment

    • dejikadri
      New Member
      • Oct 2007
      • 2

      #3
      the parameter $$params = 'amine'; must be passed as an array not a string.


      Originally posted by amine
      Hello People,
      I created a WebService in .NET on my machine with following methode:

      Code:
       <WebMethod(Description:="test")> _ 
      Public Function sayHello(ByVal myName As String, ByVal myID As Integer) As String
      Return "Hello " & myName & " (" & myID & ")"
      End Function
      Web service works fine, I can access my function in .NET without problem.
      I can also access the function using PHP and NuSOAP however I CANNOT pass the parameters, so the result of my php page is only:
      "Hello ()"

      hereby is some php code I'm using:
      What am I doing false:

      Code:
       <?php 
       
      /*NuSOAP*/
      require_once('NuSOAP/nusoap.php');
      $proxyhost = isset( $POST['proxyhost']) ? $POST['proxyhost'] : '';
      $proxyport = isset( $POST['proxyport']) ? $POST['proxyport'] : '';
      $proxyusername = isset( $POST['proxyusername']) ? $POST['proxyusername'] : '';
      $proxypassword = isset( $POST['proxypassword']) ? $POST['proxypassword'] : '';
      $client = new soapclient('http://localhost/myWS/myWS.asmx?wsdl', true, $proxyhost, $proxyport, $proxyusername, $proxypassword);
      $err = $client->getError();
      if ($err) {
      echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
      }
      $params = 'amine';
      $result = $client->call("sayHello", $params);
      // Check for a fault
      if ($client->fault) {
      echo '<h2>Fault</h2><pre>';
      print_r($result);
      echo '</pre>';
      } else {
      // Check for errors
      $err = $client->getError();
      if ($err) {
      // Display the error
      echo '<h2>Error</h2><pre>' . $err . '</pre>';
      } else {
      // Display the result
      echo '<h2>Result</h2><pre>';
      print_r($result);
      echo '</pre>';
      }
      }
      ?>
      Last edited by Markus; Nov 28 '08, 11:32 AM. Reason: fixed code tags

      Comment

      • dejikadri
        New Member
        • Oct 2007
        • 2

        #4
        use this. it worked for me

        $params =array( 'parametername' => 'amine' );
        $result = $client->call("sayHello ", array('paramete rs' => $param));


        Originally posted by amine
        Hello People,
        I created a WebService in .NET on my machine with following methode:

        Code:
         <WebMethod(Description:="test")> _ 
        Public Function sayHello(ByVal myName As String, ByVal myID As Integer) As String
        Return "Hello " & myName & " (" & myID & ")"
        End Function
        Web service works fine, I can access my function in .NET without problem.
        I can also access the function using PHP and NuSOAP however I CANNOT pass the parameters, so the result of my php page is only:
        "Hello ()"

        hereby is some php code I'm using:
        What am I doing false:

        Code:
         <?php 
         
        /*NuSOAP*/
        require_once('NuSOAP/nusoap.php');
        $proxyhost = isset( $POST['proxyhost']) ? $POST['proxyhost'] : '';
        $proxyport = isset( $POST['proxyport']) ? $POST['proxyport'] : '';
        $proxyusername = isset( $POST['proxyusername']) ? $POST['proxyusername'] : '';
        $proxypassword = isset( $POST['proxypassword']) ? $POST['proxypassword'] : '';
        $client = new soapclient('http://localhost/myWS/myWS.asmx?wsdl', true, $proxyhost, $proxyport, $proxyusername, $proxypassword);
        $err = $client->getError();
        if ($err) {
        echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
        }
        $params = 'amine';
        $result = $client->call("sayHello", $params);
        // Check for a fault
        if ($client->fault) {
        echo '<h2>Fault</h2><pre>';
        print_r($result);
        echo '</pre>';
        } else {
        // Check for errors
        $err = $client->getError();
        if ($err) {
        // Display the error
        echo '<h2>Error</h2><pre>' . $err . '</pre>';
        } else {
        // Display the result
        echo '<h2>Result</h2><pre>';
        print_r($result);
        echo '</pre>';
        }
        }
        ?>
        Last edited by Markus; Nov 28 '08, 11:33 AM. Reason: fixed code tags

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

          #5
          This thread was hooked by a member with a new problem regarding this subject. That post has been split off this thread and is now continued in a new thread http://www.thescripts.com/forum/thread781339.html in this mforum.

          moderator

          Comment

          • heshanmw
            New Member
            • Nov 2008
            • 1

            #6
            /using-nusoap-consume-net-web-service-10-min

            This also may hepfull to you

            using NuSoap: consume a .NET web service in 10 min | HEIDI Software

            Comment

            • jacanon7
              New Member
              • Aug 2009
              • 1

              #7
              Hello

              I did two web services manageSession.a smx and manageStaff.asm x

              I consume them with nusoap, first start session, sencond try to get the staff list but it displays The session is not set, .net pages I have solved the problem but in php no.

              All your help is wellcome

              Comment

              Working...