2013-02-11 40 views
2

我有一個在asp.net中創建並在iis 5.1中發佈的web服務。現在我想從php環境中調用這個web服務。其實我的Web服務獲取一個字符串作爲參數,並返回相同的字符串。但始終,返回的字符串是空的或null.I無法發送字符串值從PHP到asp.net的Web服務...如何從PHP調用我的asp.net web服務?

這在asp.net

namespace PRS_WS 
{ 
    [WebService(Namespace = "http://tempuri.org/")] 
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
    [System.ComponentModel.ToolboxItem(false)] 
    // 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 prs_point : System.Web.Services.WebService 
    { 
     [WebMethod] 
     public string testAssignment(string inputData) 
     { 
      return inputData;   
     } 
    } 
} 

而創建我的web服務,這是我調用上述asp.net web服務的PHP代碼...

<?php 
     require_once('nusoap/lib/nusoap.php'); 
     $wsdl="http://localhost/prs_point/prs_point.asmx?WSDL"; 
     $str1=""; 
     $str1="Hello from php"; 

     $client = new soapclient($wsdl,'wsdl'); 
     $result=$client->call('testAssignment',$str1); 

     foreach($result as $key => $value) 
     { 
       echo "<br/>Response ::::: $value"; 
     } 
?> 

我不知道是否需要在PHP端或asp.net端進行更改?...請指導我解決這個問題...

回答

6

此代碼工作正常,我...

<?php 

require 'nusoap/lib/nusoap.php'; 
$client = new nusoap_client('http://localhost/prs_point/prs_point.asmx?WSDL', 'WSDL'); 


$error = $client->getError(); 
if ($error) { 
    die("client construction error: {$error}\n"); 
} 

$param = array('inputData' => 'sample data'); 
$answer = $client->call('testAssignment', array('parameters' => $param), '', '', false, true); 

$error = $client->getError(); 
if ($error) { 
    print_r($client->response); 
    print_r($client->getDebug()); 
    die(); 
} 

print_r($answer); 

?> 
+0

謝謝你,Saravanan。 – PhatHV 2014-06-23 07:44:18

0

試試這個。

$client = new SoapClient("http://localhost/prs_point/prs_point.asmx?WSDL"); 
$params->inputData= 'Hello'; 

$result = $client->testAssignment($params)->testAssignmentResult; 

echo $result; 
+0

我想你的代碼...但它拋出下面的錯誤...致命錯誤:調用未定義的方法SoapClient的: :testAssignment()在第11行的C:\ wamp \ www \ soap \ tets.php – Saravanan 2013-02-11 12:20:38

+0

請幫助我解決此問題... – Saravanan 2013-02-11 12:21:24

0

你會過得更好的方法是定義在WCF服務,這讓你在生成的SOAP更多的控制,雖然我不知道關於PHP,我曾在過去獲得ASMX Web服務問題與Adobe Flex一起工作,因此儘管它仍然使用SOAP協議,但集成並不總是毫無意義。此外,你的服務看起來不錯,但我不認爲你需要這些行:

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
[System.ComponentModel.ToolboxItem(false)] 

從PHP端,你應該能夠調用$result = $client -> testAssignment($str1);但(我忘了),你可能需要訪問結果值$result = $client -> testAssignment($str1) -> testAssignmentResult;您還必須將參數傳遞給數組中捆綁的方法,而不是使用多個參數調用,有關完整示例,請參見this article

HTH