469,338 Members | 8,654 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,338 developers. It's quick & easy.

Consuming .Net WebService with PHP and NuSOAP

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

Expand|Select|Wrap|Line Numbers
  1.  <WebMethod(Description:="test")> _ 
  2. Public Function sayHello(ByVal myName As String, ByVal myID As Integer) As String
  3. Return "Hello " & myName & " (" & myID & ")"
  4. End Function
  5.  
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:

Expand|Select|Wrap|Line Numbers
  1.  <?php 
  2.  
  3. /*NuSOAP*/
  4. require_once('NuSOAP/nusoap.php');
  5. $proxyhost = isset( $POST['proxyhost']) ? $POST['proxyhost'] : '';
  6. $proxyport = isset( $POST['proxyport']) ? $POST['proxyport'] : '';
  7. $proxyusername = isset( $POST['proxyusername']) ? $POST['proxyusername'] : '';
  8. $proxypassword = isset( $POST['proxypassword']) ? $POST['proxypassword'] : '';
  9. $client = new soapclient('http://localhost/myWS/myWS.asmx?wsdl', true, $proxyhost, $proxyport, $proxyusername, $proxypassword);
  10. $err = $client->getError();
  11. if ($err) {
  12. echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
  13. }
  14. $params = 'amine';
  15. $result = $client->call("sayHello", $params);
  16. // Check for a fault
  17. if ($client->fault) {
  18. echo '<h2>Fault</h2><pre>';
  19. print_r($result);
  20. echo '</pre>';
  21. } else {
  22. // Check for errors
  23. $err = $client->getError();
  24. if ($err) {
  25. // Display the error
  26. echo '<h2>Error</h2><pre>' . $err . '</pre>';
  27. } else {
  28. // Display the result
  29. echo '<h2>Result</h2><pre>';
  30. print_r($result);
  31. echo '</pre>';
  32. }
  33. }
  34. ?>
  35.  
Sep 4 '06 #1
6 20557
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.

Expand|Select|Wrap|Line Numbers
  1.  
  2. $client = new soapclient('http://localhost/myWS/myWS.asmx?wsdl', true, $proxyhost, $proxyport, $proxyusername, $proxypassword);
  3. $err = $client->getError();
  4. $params = array('parameters' => array ('name' => 'amine'));
  5. $result = $client->call("sayHello", $params);
  6.  
  7.  
Feb 14 '07 #2
the parameter $$params = 'amine'; must be passed as an array not a string.


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

Expand|Select|Wrap|Line Numbers
  1.  <WebMethod(Description:="test")> _ 
  2. Public Function sayHello(ByVal myName As String, ByVal myID As Integer) As String
  3. Return "Hello " & myName & " (" & myID & ")"
  4. End Function
  5.  
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:

Expand|Select|Wrap|Line Numbers
  1.  <?php 
  2.  
  3. /*NuSOAP*/
  4. require_once('NuSOAP/nusoap.php');
  5. $proxyhost = isset( $POST['proxyhost']) ? $POST['proxyhost'] : '';
  6. $proxyport = isset( $POST['proxyport']) ? $POST['proxyport'] : '';
  7. $proxyusername = isset( $POST['proxyusername']) ? $POST['proxyusername'] : '';
  8. $proxypassword = isset( $POST['proxypassword']) ? $POST['proxypassword'] : '';
  9. $client = new soapclient('http://localhost/myWS/myWS.asmx?wsdl', true, $proxyhost, $proxyport, $proxyusername, $proxypassword);
  10. $err = $client->getError();
  11. if ($err) {
  12. echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
  13. }
  14. $params = 'amine';
  15. $result = $client->call("sayHello", $params);
  16. // Check for a fault
  17. if ($client->fault) {
  18. echo '<h2>Fault</h2><pre>';
  19. print_r($result);
  20. echo '</pre>';
  21. } else {
  22. // Check for errors
  23. $err = $client->getError();
  24. if ($err) {
  25. // Display the error
  26. echo '<h2>Error</h2><pre>' . $err . '</pre>';
  27. } else {
  28. // Display the result
  29. echo '<h2>Result</h2><pre>';
  30. print_r($result);
  31. echo '</pre>';
  32. }
  33. }
  34. ?>
  35.  
Oct 2 '07 #3
use this. it worked for me

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


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

Expand|Select|Wrap|Line Numbers
  1.  <WebMethod(Description:="test")> _ 
  2. Public Function sayHello(ByVal myName As String, ByVal myID As Integer) As String
  3. Return "Hello " & myName & " (" & myID & ")"
  4. End Function
  5.  
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:

Expand|Select|Wrap|Line Numbers
  1.  <?php 
  2.  
  3. /*NuSOAP*/
  4. require_once('NuSOAP/nusoap.php');
  5. $proxyhost = isset( $POST['proxyhost']) ? $POST['proxyhost'] : '';
  6. $proxyport = isset( $POST['proxyport']) ? $POST['proxyport'] : '';
  7. $proxyusername = isset( $POST['proxyusername']) ? $POST['proxyusername'] : '';
  8. $proxypassword = isset( $POST['proxypassword']) ? $POST['proxypassword'] : '';
  9. $client = new soapclient('http://localhost/myWS/myWS.asmx?wsdl', true, $proxyhost, $proxyport, $proxyusername, $proxypassword);
  10. $err = $client->getError();
  11. if ($err) {
  12. echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
  13. }
  14. $params = 'amine';
  15. $result = $client->call("sayHello", $params);
  16. // Check for a fault
  17. if ($client->fault) {
  18. echo '<h2>Fault</h2><pre>';
  19. print_r($result);
  20. echo '</pre>';
  21. } else {
  22. // Check for errors
  23. $err = $client->getError();
  24. if ($err) {
  25. // Display the error
  26. echo '<h2>Error</h2><pre>' . $err . '</pre>';
  27. } else {
  28. // Display the result
  29. echo '<h2>Result</h2><pre>';
  30. print_r($result);
  31. echo '</pre>';
  32. }
  33. }
  34. ?>
  35.  
Oct 2 '07 #4
ronverdonk
4,258 Expert 4TB
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
Mar 11 '08 #5
Hello

I did two web services manageSession.asmx and manageStaff.asmx

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
Aug 22 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Arne Holderbeke | last post: by
6 posts views Thread by Carlos Lozano | last post: by
1 post views Thread by Nattydreadlock | last post: by
5 posts views Thread by Preben Zacho | last post: by
4 posts views Thread by Boni | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.