无法从php脚本调用WCF服务方法

时间:2011-09-21 14:58:27

标签: php wcf

我有WCF服务。 当我尝试从.NET页面访问它时,一切正常。但是我找不到从php脚本访问它的方法。

  <system.serviceModel>
<bindings>
  <wsHttpBinding>
    <binding name="NewBinding0">
      <reliableSession inactivityTimeout="01:00:00" />
      <security mode="TransportWithMessageCredential">
        <transport clientCredentialType="Basic" />
        <message clientCredentialType="UserName" />
      </security>

    </binding>
  </wsHttpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="RegisterBehavior">
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceMetadata httpsGetEnabled="true" />
      <serviceThrottling maxConcurrentCalls="48" maxConcurrentSessions="5000"
        maxConcurrentInstances="5000" />
      <serviceCredentials>
        <userNameAuthentication userNamePasswordValidationMode="Custom"
          customUserNamePasswordValidatorType="..."
          cacheLogonTokens="true" cachedLogonTokenLifetime="01:00:00" />
      </serviceCredentials>
    </behavior>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
  <service behaviorConfiguration="RegisterBehavior" name="Riepas.WCFRiepas">
    <endpoint address="..."
      binding="wsHttpBinding" bindingConfiguration="NewBinding0" contract="...">

    </endpoint>
    <endpoint address="mex" binding="mexHttpsBinding" name="mex"
      contract="IMetadataExchange">

    </endpoint>
  </service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
 />

尝试从php连接,但它只是挂起。 :(

    $client = new SoapClient("wsdl", array(
                                           'login'    => "...",
                                            'password' => "...",
                                            'soap_version'   => SOAP_1_2));
                                            $functions = $client->__getFunctions ();
var_dump ($functions);

$parameters = array("ReqVal" => "nu?");
//$result = $client->__soapCall("GetStr", $parameters);
//$result = $client->GetStr($parameters);

函数返回normaly。

1 个答案:

答案 0 :(得分:0)

要使用php soapclient,您需要使用basicHttpBinding,而不是wsHttpBinding

有关一个非常简单的完整工作示例,请参阅我的Echo Service,其中包含a php client

这方面的缺点是您的服务不会实施WS-Reliable MessagingWS-Security。但是,如果你需要那些,有一个名为WSO2 Web Services Framework for PHP的开源派对模块,可以处理wsHttpBinding。