Silverlight4中WCF RIA DomainService与Net.Tcp Binding/Net.pipeBinding等非Htttp绑定无法兼容

出现问题:WCF RIA DomainService与Net.Tcp Binding/Net.pipeBinding等非Htttp绑定无法兼容

中文描述:提供的URI方案"net.tcp"无效,应为"http";

英文描述:The provided URI scheme 'net.tcp' is invalid; expected 'http'. Parameter name: context.ListenUriBaseAddress

问题原因:

(1)http://www.cnblogs.com/2018/archive/2010/10/25/1860746.html

(2)http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/thread/d6388487-27c1-4023-9825-71fb50596a8f

(3)http://forums.silverlight.net/forums/p/208892/493804.aspx#493804

解决方法1:

(1)在web服务端,创建类MyDomainServiceHostFactory

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.DomainServices.Hosting;
namespace WMOS.Web
{
    public class MyDomainServiceHostFactory : DomainServiceHostFactory
    {
        private static List<string> _allowedSchemes;
        static MyDomainServiceHostFactory()
        {
            MyDomainServiceHostFactory._allowedSchemes = new List<string>();
            MyDomainServiceHostFactory._allowedSchemes.Add(Uri.UriSchemeHttp);
            MyDomainServiceHostFactory._allowedSchemes.Add(Uri.UriSchemeHttps);
        }
        protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
        {
            baseAddresses = baseAddresses.Where(uri => MyDomainServiceHostFactory._allowedSchemes.Contains(uri.Scheme)).ToArray();
            return base.CreateServiceHost(serviceType, baseAddresses);
        }
    }
}
 

(2) 以例子工程中WMOSDomainService为例,注意这个服务的类型是:RIA domainService,在web.config配置文件配置如下

<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" >
      <serviceActivations>
        <add service="WMOS.RIAService.Web.WMOSDomainService" relativeAddress="Services/WMOS-RIAService-Web-WMOSDomainService.svc" factory="WMOS.Web.MyDomainServiceHostFactory"/>
       </serviceActivations>
</serviceHostingEnvironment>


 

解决方法2: 

或者还可以按照如下方法做,第一步相同,第二步操作

(1)web服务端,创建扩展名是.svc的WCF服务文件,WCF服务是:WMOS.RIAService.Web.WMOSDomainService,文件命名应当把“.”用“-”代替,例如:WMOS-RIAService-Web-WMOSDomainService.svc,严格按照这个规则命名。

(2)文件内容如下

<%@ ServiceHost Language="C#" Debug="true" Service="WMOS.RIAService.Web.WMOSDomainService" Factory="WMOS.Web.MyDomainServiceHostFactory" %>
注:不兼容的问题就出在Factory上。


附:

(1)Silverlight4 配置WCF net.tcp绑定宿主在IIS时应注意的几个问题

(2)WCF NET.TCP Protocol in Silverlight

(3)当Silverlight同时遇上TCP和HTTP的WCF服务

更新:

最新版本的RIA已经解决此问题,升级版本即可

posted on 2011-02-22 15:18  DhuXin  阅读(1148)  评论(0编辑  收藏  举报