首页 > 解决方案 > 如何在 PHP 中使用 WCF 服务?

问题描述

我有一个使用 GET 函数运行的简单 WCF 服务。当我在网络浏览器中调用它时。它工作正常。

当我尝试以下 PHP 调用时:

define('NEWLINE' , "< br />\n");
$wsdl = "https://www.***.info/Webservices/WCF/***.svc?wsdl";
Line 727: $soapClient= new SoapClient($wsdl,array('cache_wsdl' => 0));
$result = $soapClient->TestForPHP();
$soapClient = null;
echo "WCF service Return value: "." "."($result->getMessageResult)". NEWLINE;

我在调试中收到以下错误:

PHP Fatal error:  Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Could not find any usable binding services in WSDL. in /home/customer/www/staging9.***.com/public_html/wp-content/themes/hello-theme-child-master/functions.php:727

这是我的绑定在我的 web.config 文件中的样子:

<system.serviceModel>
 
    <behaviors>
      <serviceBehaviors>
        <behavior name="inculdeExceptionDetails">
          <serviceDebug includeExceptionDetailInFaults="true " />
        </behavior>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior>
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <webHttpBinding>
        <binding name="https">
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
    <protocolMapping>
      <add binding="webHttpBinding" scheme="http" />
      <add binding="webHttpBinding" scheme="https" bindingConfiguration="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 

这个 web 服务正在被其他 .NET 客户端成功使用,但这是我第一次尝试使用 PHP。我也刚刚测试过,它可以在 jquery 中工作(现在我将使用它)。老实说,我不了解我的绑定设置,尽管我记得我确实很难将其设置为适用于我的 .NET 客户端

标签: phpweb-serviceswcfsoap

解决方案


你的WCF服务使用的绑定是webHttpBinding,所以使用soapClient调用wcf服务是不正确的。你需要构造一个HTTP请求来访问你的WCF服务。你可以参考这个链接构造HTTP请求来访问WCF服务:HTTP Request


推荐阅读