简体   繁体   English

如何从php调用asp.net Web服务?

[英]how to call my asp.net web service from php?

I have one web service created in asp.net and published in iis 5.1 .Now i want to call this web service from php environment. 我有一个在asp.net中创建并在iis 5.1中发布的Web服务。现在,我想从php环境中调用此Web服务。 Actually my web service get one string as a parameter and return the same string .But all the time, the returned string is empty or null.I could not able to send string value from php to asp.net web service... 实际上我的Web服务将一个字符串作为参数并返回相同的字符串。但是一直以来,返回的字符串为空或null。我无法将字符串值从php发送到asp.net Web服务...

This is my web service created in asp.net 这是我在asp.net中创建的Web服务

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

And, this is my php code for calling the above asp.net web service... 而且,这是我用于调用上述asp.net网络服务的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";
         }
?>  

I don't know whether the changes needed in php side or asp.net side?...Please guide me to get out of this issue... 我不知道是否需要在php端或asp.net端进行更改?...请指导我摆脱此问题...

This code is working fine for me... 这段代码对我来说很好用...

<?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);

 ?> 

try this. 尝试这个。

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

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

echo $result;

You would be better off defining your service in WCF, this gives you more control over the generated SOAP, and while I'm not sure about PHP, I have had issues in the past getting ASMX web services to work with Adobe Flex so integration isn't always seemless despite the fact it still uses the SOAP protocol. 您最好在WCF中定义服务,这样可以更好地控制所生成的SOAP,尽管我不确定PHP,但过去在使ASMX Web服务与Adobe Flex一起使用时遇到了问题尽管它仍然使用SOAP协议,但并非总是如此。 Besides that your service looks fine but I don't think you need these lines: 除此之外,您的服务看起来还不错,但我认为您不需要这些行:

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

from the PHP side, you should be able to call $result = $client -> testAssignment( $str1 ); 从PHP方面,您应该可以调用$result = $client -> testAssignment( $str1 ); but (I've forgotten) you may need to access the result value $result = $client -> testAssignment( $str1 ) -> testAssignmentResult; 但是(我忘了)您可能需要访问结果值$result = $client -> testAssignment( $str1 ) -> testAssignmentResult; you also have to pass parameters to the methods bundled in arrays instead of calling with multiple arguments, see this article for a full example. 您还必须将参数传递给数组中捆绑的方法,而不是使用多个参数进行调用,有关完整示例,请参见本文

HTH HTH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM