2013-02-11 41 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