(注意:我终于自己解决了这个问题,模拟结果并不是主要问题;但是,如果有人知道为什么会发生模拟,请告诉我。)
我们有一个从 Silverlight 应用程序调用的 WCF 服务(它们由同一个 Web 应用程序托管)。与操作本身花费的时间相比,调用服务的速度非常慢。WCF 跟踪日志使它看起来花费了两秒钟以上的时间来模拟(参见第五行):
[15:32:3.193] From: Processing message 1.
[15:32:3.193] Activity boundary.
[15:32:3.193] Received a message over a channel.
[15:32:3.194] ServiceChannel information.
[15:32:5.539] Security Impersonation succeeded at the server.
[15:32:5.540] To: Execute 'MyNamespace.GetFloorplan'.
[15:32:5.540] Activity boundary.
[15:32:6.302] From: Execute 'MyNamespace.GetFloorplan'.
[15:32:6.302] Activity boundary.
[15:32:6.305] Sent a message over a channel.
[15:32:6.306] Activity boundary.
这让我感到困惑,因为我认为模拟是您需要在配置中显式启用(或从代码触发)的东西。我刚作为顾问加入这个项目,所以我还没有对整个源代码的完整概述,但是源代码中的任何地方都不存在“模拟”或“模拟”文本。更令人困惑的是,System.Threading.Thread.CurrentPrincipal.Identity
从服务内部返回一个没有名称的未经身份验证的身份,然后System.Security.Principal.WindowsIdentity.GetCurrent().Name
返回IIS APPPOOL\MyCustomAppPool
,因此模拟似乎并没有真正完成任何事情。
我们使用表单身份验证和 ASP.NET 兼容模式。当我禁用后者时(我不确定我是否可以永久执行此操作,因为可能存在依赖于它的功能我还不知道),Security Impersonation succeeded at the server
从日志中消失,但和之间的时间差Received a message over a channel.
仍然To: Execute 'MyNamespace.GetFloorplan'.
几乎两秒钟。添加[OperationBehavior(Impersonation = ImpersonationOption.NotAllowed)]
到操作没有帮助。
有谁明白这里发生了什么?(我的目标是摆脱模仿或任何占用这两秒钟的时间。)
我们在服务类上有以下属性(我知道理想情况下它们应该在接口上,但我还没有发现它们是否首先被放置在服务上):
[ServiceContract(Namespace = "")]
[SilverlightFaultBehavior]
[AspNetCompatibilityRequirements(RequirementsMode =
AspNetCompatibilityRequirementsMode.Allowed)]
这是我们的服务配置:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="SilverlightServiceBinding">
<binaryMessageEncoding />
<httpTransport />
</binding>
</customBinding>
</bindings>
<services>
<service name="MyNamespace.FloorplanService">
<endpoint address="" binding="customBinding"
bindingConfiguration="SilverlightServiceBinding"
contract="MyNamespace.FloorplanService" />
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
还有我们的客户端配置:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_FloorplanService"
maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="../Floorplan/FloorplanService.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_FloorplanService"
contract="FloorplanServiceProxy.FloorplanService"
name="BasicHttpBinding_FloorplanService" />
</client>
</system.serviceModel>