我正在使用RIA Services开发Silverlight 4应用程序,并且我有RIA Services SP1 Beta工具。
在Fiddler检查后,我的域名服务将出现在名称空间http://tempuri.org
中。
我想控制名称空间。是否可以将http://tempuri.org
替换为对我的组织更有意义的内容?
答案 0 :(得分:0)
我一直在启用SOAP的DomainServiceHost中搜索默认命名空间的最后一个实例。我仍然缺少一些,但这里是我找到的。哦,这段代码还将端点限制为https并阻止元数据生成。
using System.ServiceModel.DomainServices.Hosting;
using System;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Collections.Generic;
namespace mySite.Web.Models
{
public class DomainServiceHostFactoryEx : DomainServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
return new DomainServiceHostEx(serviceType, baseAddresses.Where(x => x.AbsoluteUri.StartsWith("https")).ToArray());
}
}
public class DomainServiceHostEx : DomainServiceHost
{
public DomainServiceHostEx(Type domainServiceType, params Uri[] baseAddresses) : base(domainServiceType, baseAddresses)
{
foreach (KeyValuePair<string, ContractDescription> currentContract in this.ImplementedContracts)
{
currentContract.Value.Namespace = "http://myWebSite.com/";
foreach (OperationDescription currentDescription in currentContract.Value.Operations)
{
currentDescription.DeclaringContract.Namespace = "http://myWebSite.com/";
foreach (OperationDescription innerCurrentDescription in currentDescription.DeclaringContract.Operations)
{
foreach (FaultDescription innerCurrentFaultDescription in innerCurrentDescription.Faults)
{
innerCurrentFaultDescription.Action.Replace("http://tempuri.org", "http://myWebSite.com/");
}
foreach (MessageDescription innerCurrentFaultDescription in innerCurrentDescription.Messages)
{
innerCurrentFaultDescription.Action.Replace("http://tempuri.org", "http://myWebSite.com/");
}
}
foreach (FaultDescription currentFaultDescription in currentDescription.Faults)
{
currentFaultDescription.Action.Replace("http://tempuri.org", "http://myWebSite.com/");
}
foreach (MessageDescription currentMessageDescription in currentDescription.Messages)
{
currentMessageDescription.Action.Replace("http://tempuri.org", "http://myWebSite.com/");
}
}
}
}
protected override void AddDefaultBehaviors()
{
base.AddDefaultBehaviors();
this.Description.Behaviors.Find<ServiceMetadataBehavior>().HttpsGetEnabled = false;
this.Description.Namespace = "http://myWebSite.com/";
}
}
}
您必须使用服务端点(即/Services/mySite-Web-Models-myDomainService.svc)在根目录或Services文件夹中创建一个.svc文件,其中包含以下代码:
<%@ ServiceHost Service="mySite.Web.Models.myDomainService"
Factory="mySite.Web.Models.DomainServiceHostFactoryEx" %>