web-dev-qa-db-fra.com

Appelez le service Web asp.net à partir de PHP avec plusieurs paramètres

J'utilise une méthode utilisant la classe SoapClient dans une page php pour appeler un service Web dans un site asp.net.

Voici le code php. 

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

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

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

echo $result;

Le problème est que je ne récupère que le premier paramètre (Param1) "Bonjour" et qu'il semble y avoir un problème avec Param2. Voici la méthode asp.net.

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

Que manque-t-il pour obtenir Hello World! dans la réponse?

11
Felasfaw

Essayez comme ça:

$client = new SoapClient("http://testurl/Test.asmx?WSDL");
$params->Param1 = 'Hello';
$params->Param2 = 'World!';    
$result = $client->TestMethod($params)->TestMethodResult;
20
Darin Dimitrov
***********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;
        }

    }
1
M.Ganji

J'étais en train de googler pour un appel multiparamétrique. Tous les threads n'ont pas dit ce qui suit. Lorsque php appelle le service Web .asmx, le passage de paramètres DOIT CORRIGER avec les variables utilisées dans le service Web de :

public string XYZ(string p, string q) 

L'appel de service Web doit être quelque chose comme:

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

les paires p, q doivent être nommées et clarifiées dans un appel php. 

1
TLCW