WCF服务返回HTTP 200标头,然后超时而不返回任何内容

时间:2010-07-22 21:43:37

标签: c# .net silverlight wcf web-services

我有一个Silverlight 4用户控件,用于调用驻留在ASP.NET 4 Web应用程序中的WCF服务。

启用对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();

以下是用于调用Web服务的Silverlight项目中的ClientConfig:

<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;
        }
    }

以下是web apps web.config文件中的serviceModel部分:

 <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 个答案:

答案 0 :(得分:2)

通过放置行

切换到客户端HTTP处理
 WebRequest.RegisterPrefix( "http://", WebRequestCreator.ClientHttp );
MainPage()构造函数中的

立即修复了这个问题,适用于所有浏览器。我不知道为什么或如何,但我只是接受它并继续前进。

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