2013-04-24 79 views
0

我試圖使用wsHttpBinding作爲Windows Azure角色部署WCF服務。無法在Azure Web角色上設置wsHttpBinding。 Web.config忽略?

當客戶端試圖連接到它,它不斷收到以下異常:

[SynchronizingContextState.Process] [System.Net.WebException: The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..] 
    at System.Net.HttpWebRequest.GetResponse() 
    at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) 

這似乎表明,該服務使用basicHttpBinding代替。但是,我多次查看了我的Web.config,似乎無法找到任何錯誤。此外,在Azure外部託管時,相同的服務也可以完美地工作。

我連接到Azure虛擬機並確認部署了正確的Web.config,但它看起來好像只是被忽略,因爲我無法獲取服務元數據,即使它被假定啓用。

這是我的Web.config文件:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </configSections> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> 
    </entityFramework> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    <customErrors mode="Off" /> 
    </system.web> 
    <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="BackendServiceBehavior"> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
      <serviceMetadata httpGetEnabled="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="BackendServiceBinding" maxReceivedMessageSize="655360"> 
      <security mode="None" /> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    <services> 
     <service name="MyNamespace.BackendService" behaviorConfiguration="BackendServiceBehavior"> 
     <endpoint name="Backend" address="" binding="wsHttpBinding" bindingConfiguration="BackendServiceBinding" contract="MyNamespace.IBackendService" /> 
     <endpoint name="BackendMex" address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost/BackendService.svc" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    </system.serviceModel> 
</configuration> 

我在這裏失去了一些東西?非常感謝你。

回答

0

好吧,我終於固定它,它是PEBKAC不好的情況下。 =/

我見過有人有同樣的問題,因爲他沒有在服務名稱中包含名稱空間,所以我懷疑這是一個命名空間問題,但我一直在看錯誤的地方。

原來,服務的Azure實現是在錯誤的名稱空間中定義的。我糾正它和voilá,現在它工作。

希望這對其他人至少有用。

1

您是否嘗試添加端點行爲?

<behavior name="web"> 
    <webHttp /> 
</behavior> 

(如果你想MEX是工作做了它太)

+0

那麼,事實證明這是一個命名空間問題,但我看錯了地方。謝謝你的回答! – 2013-04-25 20:22:09