【问题标题】:WCF service returns HTTP 200 header and then times out without returning any contentWCF 服务返回 HTTP 200 标头,然后超时而不返回任何内容
【发布时间】:2010-07-22 21:43:37
【问题描述】:

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

启用对网络服务的匿名访问。 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

这是调用 web 服务的 MainPage.xaml.cs 中的代码:

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

这里是 Silverlight 项目中用于调用 web 服务的 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 应用程序 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>

【问题讨论】:

  • 注释掉CloseAsync还会出现吗?这对我来说看起来不对,你为什么要关闭一个你还没有完成使用的对象(异步读取还没有完成)?
  • 是的,CloseAsync 似乎根本没有改变服务的行为(它仍然在 localhost 上工作)。

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


【解决方案1】:

通过放置该行切换到客户端 HTTP 处理

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

在 MainPage() 构造函数中立即为所有浏览器修复了这个问题。我不知道为什么或如何,但我只是接受它并在这一点上继续前进。

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

【讨论】:

  • 在所有其他浏览器中是否超时?
  • 它在 IE 中短暂工作过(我认为是 Chrome,但我只测试过一次,不记得了),但在 Firefox 中从来没有。在过去的三天里,这三天都在超时。
猜你喜欢
  • 1970-01-01
  • 2021-01-26
  • 1970-01-01
  • 1970-01-01
  • 2016-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多