2015-04-18 90 views
0

我使用Asp.net的工作,但它是我的第3天學習P​​HP ...使用WCF服務與PHP

我想使用WCF的Web服務的一個非常非常簡單的例子,並從消費它PHP網站。我把這個例子:Using WCF Services with PHP

我敢肯定,我做的一切都是它表明的方式,這裏是PHP代碼:

<?php 

$wcfClient = new SoapClient('http://localhost:8732/Design_Time_Addresses/Translation/Service1/?wsdl'); 

$args = array('text' => 'Hello World'); 
$response = $wcfClient->ENtoJP($args); 

echo $response->ENtoJPResult; 
?> 

但我仍然有下面的錯誤頁面:

Fatal error: Uncaught SoapFault exception: [HTTP] Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'. in C:\wamp\www\geogram.php:6 Stack trace: #0 [internal function]: SoapClient->__doRequest('http://localhos...', ' http://tempuri ....', 1, 0) #1 C:\wamp\www\geogram.php(6): SoapClient->__call('ENtoJP', Array) #2 C:\wamp\www\geogram.php(6): SoapClient->ENtoJP(Array) #3 {main} thrown in C:\wamp\www\geogram.php on line 6

Error Message

這裏是我的配置文件:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 

    <system.web> 
    <compilation debug="true" /> 
    </system.web> 
    <!-- Lors du déploiement du projet de bibliothèque du service, le contenu du fichier de configuration doit être ajouté au fichier app.config 
    de l'hôte. System.Configuration ne prend pas en charge les fichiers de configuration pour les bibliothèques. --> 
    <system.serviceModel> 
    <services> 
     <service name="Translation.Translation"> 
     <endpoint address="" binding="wsHttpBinding" contract="Translation.ITranslation"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8732/Design_Time_Addresses/Translation/Service1/" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <!-- Pour éviter la divulgation des informations sur les métadonnées, 
      définissez la valeur ci-dessous sur false et supprimez le point de terminaison des métadonnées ci-dessus avant le déploiement --> 
      <serviceMetadata httpGetEnabled="True"/> 
      <!-- Pour recevoir les détails d'exception des erreurs à des fins de débogage, 
      définissez la valeur ci-dessous sur true. Définissez-la sur false avant le déploiement 
      pour éviter la divulgation des informations d'exception --> 
      <serviceDebug includeExceptionDetailInFaults="False" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 

</configuration> 

我不知道問題出在哪裏,或者如何調試這個錯誤,請大家幫忙!

+0

,因爲它出現在Web瀏覽器,請複製粘貼錯誤,它有點難以讀取它現在的方式。 – Cristik

+0

這就是它出現的原因:(... –

+0

然後,請創建一個包含該內容的html文件,並粘貼在瀏覽器中打開該html時所看到的內容,這將使人們更容易閱讀錯誤 – Cristik

回答

0

肥皂請求失敗,因爲假定的webservice沒有返回正確的內容類型(content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8')。這可能有幾個原因,你需要調查它們適用於你:

  1. 您在PHP中創建SoapClient時指定了無效的webservice url。我看到你的網址中有Service1.asmx/?wsdl,不應該是Service1.asmx?wsdlService1.wsdl?無論如何,ASP.NET項目在啓動項目時應該爲您提供正確的URL。
  2. 的web服務不運行,但8732端口被另一個IIS實例
  3. 的web服務已啓動,但它的故障,您可以在創建SoapClient的時候使用trace選項找出請求和響應(看到constructor doc關於如何設置它的細節,並__getLastResponse()/__getLastResponseHeaders()