2012-03-14 20 views
10

Bir asp.net sitesinde bir web hizmetini çağırmak için bir php sayfasında SoapClient sınıfını kullanarak bir yöntem kullanıyorum.PHP'den asp.net web hizmetini birden çok parametreyle arayın

İşte php kodu.

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

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

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

echo $result; 

sorun sadece geri birinci parametre (Param1) "Merhaba" alıyorum, ve PARAM2 bir sorun var gibi görünüyor. İşte asp.net yöntemi. Ben cevaben Hello World! almak için ne eksik

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

?

cevap

19

böyle deneyin: Ben çok parametreli arama için googling

$client = new SoapClient("http://testurl/Test.asmx?WSDL"); 
$params->Param1 = 'Hello'; 
$params->Param2 = 'World!';  
$result = $client->TestMethod($params)->TestMethodResult; 
+0

... işe yaradı! Teşekkür ederim! – Felasfaw

+0

Tek bir soru. Kodumun çalışmadığı nedenden dolayı, b/c, tek tip bir param dizisi olarak geçiyordu? – Felasfaw

+0

@Felasfaw, yeap. –

1
***********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; 
     } 

    } 
+0

$ result2 = $ client-> ShowNameFamely ($ params) -> ShowNameFamelyResult; –

1

. Tüm iş parçacığı aşağıdakileri söylemedi. php aramalarının .Asmx web hizmeti, parametrelerin geçen web hizmetinde kullanılan değişkenleri UYGUN OLMALIDIR Ne zaman: web hizmeti çağrısı gibi bir şey olmak zorunda

public string XYZ(string p, string q) 

:

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

p q çiftleri php çağrısında isimlendirilmeli ve açıklığa kavuşturulmalıdır.

İlgili konular