简体   繁体   中英

Cannot access WCF in IIS from PHP SOAP

We have two instance of same WCF service, one running in the Visual Studio 2010 (IIS Express) and another in the IIS Server 7. We are using PHP5 native SOAP calls to access the Service.

While accessing the Visual Studio Instance, it works well without any problem. But when trying to access the IIS 7 instance, we are getting an Uncaught SoapFault exception as follows:

PHP Fatal error:  SOAP-ERROR: Parsing Schema: can't import schema from 'http://example.com/WCFService/Service.svc?xsd=xsd0' in C:\\xampp\\htdocs\\synergy_client\\test.php on line 2
PHP Fatal error:  Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing Schema: can't import schema from 'http://example.com/WCFService/Service.svc?xsd=xsd0' in C:\\xampp\\htdocs\\synergy_client\\test.php:2\nStack trace:\n#0 C:\\xampp\\htdocs\\synergy_client\\test.php(2): SoapClient->SoapClient('[http://]example.com...')\n#1 {main}\n  thrown in C:\\xampp\\htdocs\\synergy_client\\test.php on line 2

The PHP code used to access the service is:

<?php
$client = new SoapClient("[http://]example.com/WCFService/Service.svc?wsdl");
$result2 = $client->LoginAdmin(array('username' => "username",'password' => "password"));

web.conf of the IIS 7 Instance is:

    <?xml version="1.0"?>
   <configuration>
    <system.web>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.0">
    <assemblies>
        <add assembly=...../>
      </assemblies>
    </compilation>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

web.conf of Visual Studio Instance(which is running as expected):

    <?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

As we are new to .Net, we need your help to solve the issue.

Additional Info: localhost replaced by example.com [http://] for http://, as I cannot place links.

Edit: This is the script generated whe accessing the wsdl directly in a browser.

<wsdl:definitions name="Service" targetNamespace="http://tempuri.org/">
<wsdl:types><xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://localhost/WCFService/Service.svc?xsd=xsd0" namespace="http://tempuri.org/"/>
<xsd:import schemaLocation="http://localhost/WCFService/Service.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
<xsd:import schemaLocation="http://localhost/WCFService/Service.svc?xsd=xsd2" namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
</xsd:schema></wsdl:types><wsdl:message name="IService_LoginAdmin_InputMessage"><wsdl:part name="parameters" element="tns:LoginAdmin"/>
</wsdl:message>
.......

Change the schemalocation because the phpclient is probably not running on the same server as the wcf service is hosted. You can change it in the serviceMetadata:

<serviceMetadata httpGetEnabled="true" httpGetUrl="http://example.com/WCFService/Service.svc"  />

Source: How to change the default schemalocation in wsdl file of WCf Service?

Got the solution! Thank you Luuk for your prompt response and time to sugget the solutions, as it was saying

`can't import schema from http://example.com/WCFService/Service.svc?xsd=xsd0'

I tried to access the schema link through browser and got 404 error. Then Googled for that and found the following solution.

Allow access for IIS_IUSERS to the folder 'C:/Windows/Temp'

Hope this answer helps someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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