15

I'm using a method using SoapClient class in a php page to call a web service in an asp.net site.

Here is the php code.

$client = new SoapClient("http://testurl/Test.asmx?WSDL");

$params = array( 'Param1'  => 'Hello', 
                'Param2' => 'World!');

$result = $client->TestMethod($params)->TestMethodResult;

echo $result;

The problem is, I'm only getting the first parameter (Param1) "Hello" back and seems like there is an issue with Param2. Here is the asp.net method.

[WebMethod]
public string TestMethod(string Param1, string Param2) 
{
    return Param1 + " " +  Param2; 
}

What am I missing to get Hello World! in the response?

VMAtm
  • 27,943
  • 17
  • 79
  • 125
Felasfaw
  • 571
  • 2
  • 7
  • 20

3 Answers3

26

Try like this:

$client = new SoapClient("http://testurl/Test.asmx?WSDL");
$params->Param1 = 'Hello';
$params->Param2 = 'World!';    
$result = $client->TestMethod($params)->TestMethodResult;
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
1

I was googling for multi-parameter calling. All the thread did not tell the following. When php call .asmx web service, the passing of parameters MUST MATCH the variables used in the web service of :

public string XYZ(string p, string q) 

The web service call has to be something like :

$params = array( "p"  => $name1,    "q" => $name2 );

p, q pairs must be named and clarified in php calling.

Draken
  • 3,134
  • 13
  • 34
  • 54
TLCW
  • 33
  • 5
0
***********index.php******************
<?php
require_once("lib/nusoap.php"); 
 $client = new SoapClient("http://localhost:1966/ListAndishmandan/WebServiseFinal.asmx?WSDL");

    $params = array( 'Param1'  => 'Moslem', 
                    'Param2' => 'Ganji!');

    $result = $client->TestMethod($params)->TestMethodResult;

    print_r( $result);
    $params = array( 'Param1'  => 'Moslem', 
                    'Param2' => 'Ganji!');
echo "\n \r";
    $result2 = $client->ShowNameFamely($params)->ShowNameFamelyResult;

    print_r( $result2);
?>

    *******************WebServiseFinal.asmx?WSDL**************************
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;

    /// <summary>
    /// Summary description for WebServiseFinal
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
     [System.Web.Script.Services.ScriptService]
    public class WebServiseFinal : System.Web.Services.WebService {

        public WebServiseFinal () {

            //Uncomment the following line if using designed components 
           //InitializeComponent(); 
        }

        [WebMethod]
        public string HelloWorld() {
            return "Hello World";
        }
        [WebMethod]
        public string TestMethod(string Param1, string Param2)
        {
            return Param1 + " " + Param2;
        }

        [WebMethod]
        public string ShowNameFamely(string Param1, string Param2)
        {
            return Param1 + " " + Param2;
        }

    }
M.Ganji
  • 818
  • 8
  • 13