无法使用 C# Web 服务将 PHP 中的 stdClass 转换为字符串

Cannot convert stdClass to String in PHP using C# web service

所以,我知道这个问题已经被问了很多,但我正在尽可能多地进行研究,但我找不到适合我的答案。

我有一个项目的 C# Web 服务,作为演示,我正在尝试做这样的事情:

[WebMethod]
public string GetResponse(string input)
{
    return "You entered " + input + ".";
}

在PHP中:

<?php
    $client = new SoapClient("http://localhost:49283/MyService.asmx?wsdl");
    $client->GetResponse("hello");
?>
当您使用 Web 服务的主页调用它时,

Return 值如下所示(URL 是 http://localhost:49283/BookService.asmx/GetResponse?input=hello):

<string xmlns="http://tempuri.org/">You entered hello.</string>

执行 var_dump 响应如下所示:

object(stdClass)#2 (1) { ["GetResponseResult"]=> string(13) "You entered ." }

所以我知道它里面有一个字符串,但我不知道如何"extract"它从对象中取出来。有人可以帮忙吗?

您可以使用 $result->GetResponseResult 测试此代码来访问该值:

<?php
    $client = new SoapClient("http://localhost:49283/MyService.asmx?wsdl");
    $result = $client->GetResponse("hello");
    echo $result->GetResponseResult;
?>

使用 $obj->GetResponseResultobject(stdClass)#2 (1) { ["GetResponseResult"]=> string(13) "You entered ." }

中获取结果
<?php
    $client = new SoapClient("http://localhost:49283/MyService.asmx?wsdl");
    $obj = $client->GetResponse("hello");
    echo $obj->GetResponseResult;
?>