从IIS中托管的ASP.NET Web应用程序接收WCF回调服务

时间:2013-03-11 23:36:25

标签: asp.net wcf iis-6 xbap wcf-callbacks

我已经在这个问题上工作了几天了。

问题有3个工作部分。 我有一个ASP.NET站点,WCF IIS托管服务和WPF xbap应用程序。

我要做的是将变量从ASP.NET站点传递到WPF xbap应用程序。所以我使用wsDualHttpBinding设置了一个WCF服务,并使用回调来通知ASP.NET和xbap。

现在,当我在服务器上的IIS 6中托管WCF服务并在本地运行VS2012 iisexpress和本地xbap时运行ASP.NET托管。它工作正常。 但是,只要我将ASP.NET站点发布到服务器上的IIS 6,ASP.NET应用程序就不会收到回调。两者都在应用程序池中。

是否有设置,或者我需要寻找的东西让ASP.NET保持打开回调的监听端口? XBAP仍在接收回调,没问题。

服务配置如下:(注意我已经将缓冲区最大化,因为目前很简单,以便将其排除在外)

<configuration>
  <system.diagnostics>
    <sources>
      <source propagateActivity="true" name="System.ServiceModel" switchValue="Warning,ActivityTracing">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="ServiceModelTraceListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
       <add initializeData="web_tracelog.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
        <filter type="" />
      </add>
    </sharedListeners>
  </system.diagnostics>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <bindings>
     <wsDualHttpBinding>
        <binding receiveTimeout="00:01:00" sendTimeout="00:00:05" maxReceivedMessageSize="2147483647"
      messageEncoding="Text" textEncoding="utf-8">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None" />
        </binding>
      </wsDualHttpBinding>
    </bindings>
    <behaviors>      
      <serviceBehaviors>
        <behavior>
         <serviceMetadata httpGetEnabled="true"/>
         <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="false"
  multipleSiteBindingsEnabled="false" />
    <protocolMapping>
      <add scheme="http" binding="wsDualHttpBinding" />
    </protocolMapping>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>
   </system.webServer>
</configuration>

该服务具有客户端将订阅回调列表的方法。然后方法将通过列表递增以发送调用回调。

[ServiceContract(CallbackContract = typeof(IClientCallback))]
public interface IVisualisationService
{
    [OperationContract(IsOneWay = true)]
    void SubscribeToRedenderHoles(string address);

    [OperationContract(IsOneWay = true)]
    void SubscribeToEditSelectedHoles(string address);

    [OperationContract(IsOneWay = true)]
    void SubscribeToShowHoles(string address);

    [OperationContract(IsOneWay = true)]
    void RedenderHoles(Hole3D[] holes, string address, int channelhashcode);

    [OperationContract(IsOneWay = true)]
    void EditSelectedHoles(Guid[] holesIds, string address);

    [OperationContract(IsOneWay = true)]
    void ShowHoles(string address);


}

public interface IClientCallback
{
    [OperationContract(IsOneWay = true)]
    void OnRenderHoles(Hole3D[] holes);

    [OperationContract(IsOneWay = true)]
    void OnEditSelectedHoles(Guid[] holesIds);

    [OperationContract(IsOneWay = true)]
    void OnShowHoles(int channelhashcode);
}

下面是WCF服务标题,我已经跳过了方法。

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class VisualisationService : IVisualisationService
{

现在为ASP.NET Client web.config

<system.serviceModel>
    <bindings>
        <wsDualHttpBinding>
            <binding name="WSDualHttpBinding_IVisualisationService" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" >
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
              <security mode="None" />
            </binding>
        </wsDualHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://hims.mecha.com/VisualisationWcfService/VisualisationService.svc"
            binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IVisualisationService"
            contract="VisualisationServiceReference.IVisualisationService"
            name="WSDualHttpBinding_IVisualisationService" />
    </client>
</system.serviceModel>

然后是XBAP app客户端app.config

<configuration>
    <system.serviceModel>
        <bindings>
            <wsDualHttpBinding>
                <binding name="WSDualHttpBinding_IVisualisationService"     maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" >
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>

                    <security mode="None" />
                </binding>
            </wsDualHttpBinding>
        </bindings>
        <client>
          <endpoint address="http://hims.mecha.com/VisualisationWcfService/VisualisationService.svc"        
            binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IVisualisationService"
            contract="VisualisationService.IVisualisationService" name="WSDualHttpBinding_IVisualisationService" />
        </client>
    </system.serviceModel>
</configuration>

在两个客户端中,我使用了“添加服务引用”方法,将WCF添加到ASP.NET和XBAP项目中。 我已经设置了两个客户端来获取代码,当然还要处理每个回调的方法。

sealed class VisualisationManager : VisualisationService.IVisualisationServiceCallback

我知道它看起来有点长,但我想尽可能多地展示这个问题。我完全迷失了,为什么它在本地工作正常,但在IIS 6中托管时却没有。

1 个答案:

答案 0 :(得分:0)

迟到的答案,但是如果像我这样的人通过Big G来解决这个问题。

我有类似的问题,我的解决方案是将CallbackBehavior添加到实现回调接口的类中(在您的情况下; IClientCallback)。像这样:

[CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)]
public class ClientCallback : IClientCallback
...

希望得到这个帮助。