2010-07-22 117 views
1

我有一個Silverlight 4用戶控件,它調用駐留在ASP.NET 4 Web應用程序中的WCF服務。WCF服務返回HTTP 200頭,然後超時而不返回任何內容

啓用匿名訪問web服務。 clientaccesspolicy.xml已準備好並且已成功下載。正確導航到服務器上的FieldITDbService.svc會提取服務元數據。

然而,當我嘗試查看測試頁面調用該WCF服務的Silverlight控件,服務本身返回:不返回數據

HTTP/1.1 200 OK 
Date: Thu, 22 Jul 2010 21:15:54 GMT 
Server: Microsoft-IIS/6.0 
X-Powered-By: ASP.NET 
X-AspNet-Version: 4.0.30319 
Content-Encoding: gzip 
Content-Length: 4409 
Cache-Control: private 
Content-Type: application/soap+msbin1 

然後超時。我很困惑。有誰知道爲什麼會發生這種情況,或者我可以如何更有效地進行調試?我跟蹤記錄服務,但日誌中沒有錯誤 - 根據日誌,它正在工作。

這裏的顯示會發生什麼的鏈接(來自Fiddler2):http://imgur.com/VwgqS.png

下面是MainPage.xaml.cs中調用WebService的代碼:

var webService = new FieldITDbServiceClient(); 
webService.ReadVAMDataCompleted += webService_ReadVAMDataCompleted; 
webService.ReadVAMDataAsync(); 
webService.CloseAsync(); 

這裏是ClientConfig在Silverlight項目用來調用web服務:

<system.serviceModel> 
    <bindings> 
     <customBinding> 
      <binding name="CustomBinding_FieldITDbService"> 
       <binaryMessageEncoding /> 
       <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" /> 
      </binding> 
     </customBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://[ipofmyserverhere]/FieldIT/FieldITDBService.svc" 
      binding="customBinding" bindingConfiguration="CustomBinding_FieldITDbService" 
      contract="DbServiceRef.FieldITDbService" name="CustomBinding_FieldITDbService" /> 
    </client> 
</system.serviceModel> 

這是在實際WCF服務的代碼,FieldITDbService.svc:

[ServiceContract(Namespace = "")] 
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] 
    public class FieldITDbService 
    { 
     [OperationContract] 
     public List<VAM> ReadVAMData() 
     { 
      List<VAM> allData = new List<VAM>(); 
      using(FieldITEntities dbContext = new FieldITEntities()) 
      { 
       allData.AddRange(dbContext.VAMs.ToList()); 
      } 
      return allData; 
     } 
    } 

這裏是在紙幅的serviceModel部應用程式web.config文件:

<system.serviceModel> 
    <diagnostics> 
     <messageLogging maxMessagesToLog="100" 
      logEntireMessage="true" 
      logMessagesAtServiceLevel="true" 
      logMalformedMessages="true" 
      logMessagesAtTransportLevel="true"> 
     </messageLogging> 
    </diagnostics> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name=""> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <bindings> 
     <customBinding> 
     <binding name="FieldIT.FieldITDbService.customBinding0"> 
      <binaryMessageEncoding /> 
      <httpTransport /> 
     </binding> 
     </customBinding> 
    </bindings> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
     multipleSiteBindingsEnabled="true" /> 
    <services> 
     <service name="FieldIT.FieldITDbService"> 
     <endpoint address="" binding="customBinding" bindingConfiguration="FieldIT.FieldITDbService.customBinding0" 
      contract="FieldIT.FieldITDbService" /> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     </service> 
    </services> 
    </system.serviceModel> 
+1

如果您註釋掉'CloseAsync',還會發生嗎?對我來說,這只是看起來不對,你爲什麼要調用關閉你還沒有完成使用的對象(異步讀取還沒有完成)? – AnthonyWJones 2010-07-23 08:27:21

+0

是的,CloseAsync似乎根本不會改變服務的行爲(它仍然在它的localhost上工作)。 – 2010-07-23 17:29:14

回答

2

切換到客戶機HTTP處理通過將線

WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp); 

在的MainPage()構造立即解決此問題並適用於所有瀏覽器。我不知道爲什麼或如何,但我只是想接受它並繼續前進。

http://msdn.microsoft.com/en-us/library/dd920295%28v=VS.95%29.aspx

+0

在所有其他瀏覽器中是否超時? – 2010-07-26 20:55:15

+0

它在IE瀏覽器(我認爲Chrome,但我只測試一次,並沒有真正記得),但從來沒有在Firefox中簡要工作。在過去的三天中,這三項都是超時的。 – 2010-07-26 21:19:17