简体   繁体   English

从 PHP 客户端调用 AC# Web 服务

[英]Call A C# Web Service From PHP Client

I have this ASP.Net C# Web Service http://www.emadbook.com/TestWebService/Convert.asmx我有这个 ASP.Net C# Web 服务http://www.emadbook.com/TestWebService/Convert.asmx

and this is the PHP client code:这是 PHP 客户端代码:

    <?php
        //Use C# Web Service:
        require "lib/nusoap.php";
        $client2 = new nusoap_client("http://www.emadbook.com/TestWebService/Convert.asmx?WSDL","http://tempuri.org/");
        $result = $client2->call("CelsiusToFahrenheit", array(37));
        echo $result;
    ?>

this code return nothing and no errors anybody can modify my code to return a value, I think the main error is in passing a number to the service as I looked on google but I could not find a way of sending number parameter?这段代码什么都不返回也没有错误任何人都可以修改我的代码以返回一个值,我认为主要错误是在我在谷歌上查看时将一个数字传递给服务,但我找不到发送数字参数的方法?

Edit: I saw this link: Call asp.net web service from PHP with multiple parameters and I modified my code to:编辑:我看到了这个链接: 使用多个参数从 PHP 调用 asp.net web 服务,我将代码修改为:

<?php
    //Use C# Web Service:
    $client2 = new SoapClient("http://www.emadbook.com/TestWebService/Convert.asmx?WSDL");
    $params->Celsius = '37';   
    $result = $client2->CelsiusToFahrenheit($params)->CelsiusToFahrenheitResult;
    echo (string)$result;
?>

and it return a result but before that it show this error: Warning: Creating default object from empty value pointing to the Params variable creation, so this is good progress but any body can solve the generated error?它返回一个结果,但在此之前它显示此错误:警告:从指向 Params 变量创建的空值创建默认对象,所以这是一个很好的进展,但任何主体都可以解决生成的错误? thanks谢谢

This is the right Answer I found it by myself and I like to share it for other developers这是我自己找到的正确答案,我喜欢与其他开发人员分享

<?php
    //Use C# Web Service:
    $client2 = new SoapClient("http://www.emadbook.com/TestWebService/Convert.asmx?WSDL");
    $params = new ArrayObject();
    $params->Celsius = 37;
    $result = $client2->CelsiusToFahrenheit($params)->CelsiusToFahrenheitResult;
    echo $result;
?>

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

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