WCF over HTTPS with PHP throws “Method Not Allowed” exception

老子叫甜甜 提交于 2021-01-29 03:22:34

问题


I've created a .NET WCF service that is intended to always be over HTTPS. When I first created the service skeleton and ran it over HTTP, it worked fine. I used PHP5 to test the interoperability with the built in SOAP functions. However, once I switched to HTTPS, when I try to call the function from PHP, I get a fault back with the message "Method Not Allowed" and the fault code of "http." It does allow me to retrieve the list of methods though. The error occurs when it calls the method "Test."

Here is the WCF configuration:

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="secureBasic">
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="apiBehavior" name="TestAPI.API">
        <endpoint address="https://192.168.0.3/API" 
                  binding="basicHttpBinding" 
                  bindingConfiguration="secureBasic" 
                  contract="TestAPI.IAPI"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="apiBehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

And here is how PHP is calling it:

$client = new SoapClient("https://192.168.0.3/API.svc?wsdl");
echo "<pre>" . print_r($client->__getFunctions(), 1) . "</pre>";
$param = new stdClass();
$param->A = "123";
$param->B = "456";
try {
    $client->Test($param);
} catch (Exception $e) {
    die("<pre>" . print_r($e,1) . "</pre>");
}

I'm using a self-signed SSL certificate for testing and I don't believe PHP requires a trusted certificate.

What am I doing wrong?


回答1:


Have you tried a network sniffer to see what actually got requested from where? Something like Fiddler or Wireshark (depending on the scenario).

Also - I note that you are missing behaviorConfiguration="apiBehavior" on the <service... element.



来源:https://stackoverflow.com/questions/276389/wcf-over-https-with-php-throws-method-not-allowed-exception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!