浏览svc将提示程序集加载失败,如果出现这种情况,请将上面的“,
Version=2.0.5.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35”去掉,即改成

    <httpModules>
      <add
name=”ScriptModule” type=”System.Web.Handlers.ScriptModule,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35″/>

    </httpModules>
  </system.web>

另外,如果生成后,发现bin目录下没有System.ServiceModel.PollingDuplex.dll,可以手动复制一份到bin目录中

然后,再新建一个ASP.NET AJAX-enabled Web
site,查看默认的web.config文件,内容大致如下:

源代码下载:DuplexWcf_SL.rar
(vs2010编辑的,用vs2008打开可能需要手动修改一些地方)

 

<extensions>
      <bindingExtensions>
        <add name=”pollingDuplexHttpBinding”
  
type=”System.ServiceModel.Configuration.PollingDuplexHttpBindingCollectionElement,
System.ServiceModel.PollingDuplex,
Version=2.0.5.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35″ />
      </bindingExtensions>
    </extensions>

解决方案:

一直觉得SL中的wcf双工通讯方式有点鸡肋,如果是以http方式实现则效率太低,如果用SL4中的tcp方式实现,又跟socket太雷同,所以一直没去研究,不过这东西在对性能要求不高时(比如在网页上每5分钟更新一次天气预报/股票信息),实现起来还是蛮方便的.

 

wcf双工通讯与传统的wcf相比,最大的区别就是:传统的wcf通常都是客户端去调服务,即客户端从服务端上“拉”信息,而双工通讯除了允许客户端从服务端”拉”信息外,服务端还能主动向客户端“推”送信息。

 

2.客户端调试时,如果出现无法访问客户端,请检查服务端下有无策略文件clientaccesspolicy.xml,参考内容如下:

先新建一个普通的vs2005 web 项目,
查看默认的web.config文件,内容大致如下:

1.服务端的web.config中配置bindingExtensions时,如果按照官方的配置写法:

当运行一个asp.net 2.0  ajax
web页面或为一个已经存在的web应用程序启用Ajax功能时,原来正确的页面,可能会出现提示“
‘Sys’ is undefined“。

<extensions>
            <bindingExtensions>
                <add name=”pollingDuplexHttpBinding”
type=”System.ServiceModel.Configuration.PollingDuplexHttpBindingCollectionElement,
System.ServiceModel.PollingDuplex”/>
            </bindingExtensions>
        </extensions>

  <system.web.extensions>
    <scripting>
      <webServices>
      </webServices>
    </scripting>
  </system.web.extensions>

当然这种实现是有性能消耗的,服务端将保存一条”回调通道”以便能利用该通道把信息推到客户端,而客户端也要有相应的回调函数来处理–有点类似”ajax中的长链接”以及”服务器推”技术

  <system.web>
    <pages>
      <controls>
        <add tagPrefix=”asp” namespace=”System.Web.UI”
assembly=”System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35″/>
      </controls>

    </pages>
    <compilation
debug=”false”>
      <assemblies>
        <add assembly=”System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35″/>
      </assemblies>
    </compilation>

sl3的官方文档http://msdn.microsoft.com/zh-cn/library/dd470106(VS.95).aspx中有一个客户端把订单发送到服务端,然后由服务端处理后,再把结果回推到客户端的例子,不过sdk中有二个地方没有注明细节,可能会误导大家调试失败。

<?xml version=”1.0″?>
<configuration>
  <configSections>
    <sectionGroup name=”system.web.extensions”
type=”System.Web.Configuration.SystemWebExtensionsSectionGroup,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35″>
      <sectionGroup name=”scripting”
type=”System.Web.Configuration.ScriptingSectionGroup,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35″>
          <section name=”scriptResourceHandler”
type=”System.Web.Configuration.ScriptingScriptResourceHandlerSection,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35″ requirePermission=”false”
allowDefinition=”MachineToApplication”/>
        <sectionGroup name=”webServices”
type=”System.Web.Configuration.ScriptingWebServicesSectionGroup,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35″>
          <section name=”jsonSerialization”
type=”System.Web.Configuration.ScriptingJsonSerializationSection,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35″ requirePermission=”false”
allowDefinition=”Everywhere” />
          <section name=”profileService”
type=”System.Web.Configuration.ScriptingProfileServiceSection,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35″ requirePermission=”false”
allowDefinition=”MachineToApplication” />
          <section name=”authenticationService”
type=”System.Web.Configuration.ScriptingAuthenticationServiceSection,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35″ requirePermission=”false”
allowDefinition=”MachineToApplication” />
        </sectionGroup>
      </sectionGroup>
    </sectionGroup>
  </configSections>

<?xml version=”1.0″ encoding=”utf-8″?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from http-request-headers=”SOAPAction”>
        <domain uri=”*”/>
      </allow-from>
      <grant-to>
        <resource path=”/” include-subpaths=”true”/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>

    <httpHandlers>
      <remove verb=”*” path=”*.asmx”/>
      <add verb=”*” path=”*.asmx” validate=”false”
type=”System.Web.Script.Services.ScriptHandlerFactory,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35″/>
      <add verb=”*” path=”*_AppService.axd” validate=”false”
type=”System.Web.Script.Services.ScriptHandlerFactory,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35″/>
      <add verb=”GET,HEAD” path=”ScriptResource.axd”
type=”System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions,
Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″
validate=”false”/>

    </httpHandlers>

注意:用后一个web.config文件替换前一个web.config文件,或者将后一个文件的新增部分添加到前一个项目中的web.config文件即可。
主要是粗体部分

引起的原因有很多,最可能的一种是:
在页面上启用Ajax功能,但没有在web.config文件中增加相应的配置。

  <system.webServer>
    <validation validateIntegratedModeConfiguration=”false”/>
    <modules>
      <add name=”ScriptModule” preCondition=”integratedMode”
type=”System.Web.Handlers.ScriptModule, System.Web.Extensions,
Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35″/>
    </modules>
    <handlers>
      <remove name=”WebServiceHandlerFactory-Integrated” />
      <add name=”ScriptHandlerFactory” verb=”*” path=”*.asmx”
preCondition=”integratedMode”
           type=”System.Web.Script.Services.ScriptHandlerFactory,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35″/>
      <add name=”ScriptHandlerFactoryAppServices” verb=”*”
path=”*_AppService.axd” preCondition=”integratedMode”
           type=”System.Web.Script.Services.ScriptHandlerFactory,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35″/>
      <add name=”ScriptResource” preCondition=”integratedMode”
verb=”GET,HEAD” path=”ScriptResource.axd”
type=”System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions,
Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″
/>
    </handlers>
  </system.webServer>

</configuration>

必发bf88 1必发bf88 2Code
<?xml version=”1.0″ encoding=”utf-8″?>
<configuration>
      <appSettings/>
    <connectionStrings/>
      <system.web>
        <compilation debug=”true” />
        <authentication mode=”Windows” />
    </system.web>
</configuration>

必发bf88 3必发bf88 4Code
必发bf88 5<?xml version=”1.0″?>
必发bf88 6<configuration>
必发bf88 7  <configSections>
必发bf88 8    <sectionGroup name=”system.web.extensions” type=”System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″>
必发bf88 9      <sectionGroup name=”scripting” type=”System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″>
必发bf88 10          <section name=”scriptResourceHandler” type=”System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ requirePermission=”false” allowDefinition=”MachineToApplication”/>
必发bf88 11        <sectionGroup name=”webServices” type=”System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″>
必发bf88 12          <section name=”jsonSerialization” type=”System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ requirePermission=”false” allowDefinition=”Everywhere” />
必发bf88 13          <section name=”profileService” type=”System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ requirePermission=”false” allowDefinition=”MachineToApplication” />
必发bf88 14          <section name=”authenticationService” type=”System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ requirePermission=”false” allowDefinition=”MachineToApplication” />
必发bf88 15        </sectionGroup>
必发bf88 16      </sectionGroup>
必发bf88 17    </sectionGroup>
必发bf88 18  </configSections>
必发bf88 19
必发bf88 20  <system.web>
必发bf88 21    <pages>
必发bf88 22      <controls>
必发bf88 23        <add tagPrefix=”asp” namespace=”System.Web.UI” assembly=”System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″/>
必发bf88 24      </controls>
必发bf88 25    </pages>
必发bf88 26    <compilation debug=”false”>
必发bf88 27      <assemblies>
必发bf88 28        <add assembly=”System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″/>
必发bf88 29      </assemblies>
必发bf88 30    </compilation>
必发bf88 31
必发bf88 32    <httpHandlers>
必发bf88 33      <remove verb=”*” path=”*.asmx”/>
必发bf88 34      <add verb=”*” path=”*.asmx” validate=”false” type=”System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″/>
必发bf88 35      <add verb=”*” path=”*_AppService.axd” validate=”false” type=”System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″/>
必发bf88 36      <add verb=”GET,HEAD” path=”ScriptResource.axd” type=”System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ validate=”false”/>
必发bf88 37    </httpHandlers>
必发bf88 38
必发bf88 39    <httpModules>
必发bf88 40      <add name=”ScriptModule” type=”System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″/>
必发bf88 41    </httpModules>
必发bf88 42  </system.web>
必发bf88 43
必发bf88 44  <system.web.extensions>
必发bf88 45    <scripting>
必发bf88 46      <webServices>
必发bf88 47      </webServices>
必发bf88 48    </scripting>
必发bf88 49  </system.web.extensions>
必发bf88 50
必发bf88 51  <system.webServer>
必发bf88 52    <validation validateIntegratedModeConfiguration=”false”/>
必发bf88 53    <modules>
必发bf88 54      <add name=”ScriptModule” preCondition=”integratedMode” type=”System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″/>
必发bf88 55    </modules>
必发bf88 56    <handlers>
必发bf88 57      <remove name=”WebServiceHandlerFactory-Integrated” />
必发bf88 58      <add name=”ScriptHandlerFactory” verb=”*” path=”*.asmx” preCondition=”integratedMode”
必发bf88 59           type=”System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″/>
必发bf88 60      <add name=”ScriptHandlerFactoryAppServices” verb=”*” path=”*_AppService.axd” preCondition=”integratedMode”
必发bf88 61           type=”System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″/>
必发bf88 62      <add name=”ScriptResource” preCondition=”integratedMode” verb=”GET,HEAD” path=”ScriptResource.axd” type=”System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ />
必发bf88 63    </handlers>
必发bf88 64  </system.webServer>
必发bf88 65</configuration>
必发bf88 66

admin

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注