ASPHostCentral.com ASP.NET and Windows Hosting BLOG
All about ASP.NET 4.5 Hosting, ASP.NET 4 Hosting, ASP.NET MVC 4.0 Hosting, Sharepoint 2013 Hosting, and all Windows 2012 Hosting articles
<< ASP.NET 4 Hosting :: Working with a Database using Model-First Development Technique
|
Sharepoint Hosting :: Tricks and Traps with Site Columns and Content Types >>
WCF RIA Service Hosting :: WCF RIA Service Configuration in a Shared Hosting/Server
March 2, 2010 15:00 by
Administrator
The following article summarizes all the possible problems that may arise when deploying a WCF RIA Service application to a shared host.
ASPHostCentral.com
, as the premier ASP.NET and Windows Hosting provider, proudly presents this article to anyone and we believe it will help many ASP.NET communities; especially to those who are using WCF RIA Service. In case you are looking for WCF RIA Service Hosting, you can always consider
ASPHostCentral.com
and you can start from our lowest Standard Plan
@$4.99/month
to host your WCF-service site.
Why :
RIA framework dynamically creates WCF service (Domain services) and add endpoints to the service. It first checks if endpoint does not exist then create it, and it checks for 3 endpoints (http, SOAP and binary). After creating end points it adds authentication schema to end points. It picks IIS authentication schemas and tries to apply on end points and failed to apply.
If we could create desired end points in web.config RIA framework will not create or do anything with endpoints and it works successfully.
You just need to follow the simple steps as mentioned on the followings:
1. Add following code to you web.config to solve issue “
This collection already contains an address with scheme http..
”
<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
<baseAddressPrefixFilters>
<add prefix="http://www.yoursite.com"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
Note: Your service can be only accessed by URL mentioned in above settings. As configured above you can’t access your service via
http://yoursite.com
. You could also use factory code to host WCF (see below) to resolve this error however alone with that you need to create svc files for each domain service.
2.Add AspNetCompatibilityRequirementsMode attribute to your RIA Domain services classes
Eg .Attributes added to AuthenticationService class under services folder
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class AuthenticationService : AuthenticationBase<User> { }
RIA framework dynamically apply these attributes after creating end points. Since we are now bypassing endpoint creation, we need to manually apply these attributes.
3. For each RIA domain service add following to you configuration file.
E.g. Is shown for AuthenticationService and UserRegistrationService
Where SparkExams is my custom namespace.
<services>
<service name="SparkExams.Web.AuthenticationService"
behaviorConfiguration="RIAServiceBehavior">
<endpoint address="" binding="wsHttpBinding"
contract="SparkExams.Web.AuthenticationService" />
<endpoint address="/soap"
binding="basicHttpBinding"
contract="SparkExams.Web.AuthenticationService" />
<endpoint address="/binary"
binding="customBinding"
bindingConfiguration="BinaryHttpBinding"
contract="SparkExams.Web.AuthenticationService" />
</service>
<service name="SparkExams.Web.UserRegistrationService"
behaviorConfiguration="RIAServiceBehavior">
<endpoint address=""
binding="wsHttpBinding"
contract="SparkExams.Web.UserRegistrationService" />
<endpoint address="/soap"
binding="basicHttpBinding"
contract="SparkExams.Web.UserRegistrationService" />
<endpoint address="/binary"
binding="customBinding" bindingConfiguration="BinaryHttpBinding"
contract="SparkExams.Web.UserRegistrationService" />
</service>
Please note that RIA adds 3 endpoints and if any of these endpoints are missing from web.config it will throw "
IIS specified authentication schemes 'Basic, Anonymous'...
" error.
Add following behaviours and bindings to your web.config
<behaviors>
<serviceBehaviors>
<behavior name="RIAServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="BinaryHttpBinding">
<binaryMessageEncoding />
<httpTransport />
</binding>
</customBinding>
</bindings>
Test you WCF end points using WCF client test tool (Test client for Windows Communication Foundation services). WcfTestClient.exe : Go to VS 2008 Console and type WcfTestClient.exe.
Note that there is no need to host you service,or change IIS settings by ISP.
-----------------------------------------------------------------------------
Read further if you want to know how this configuration has been discovered...
1. Have Used Red Gate's .NET Reflector to examine RIA assemblies.
2. Plugin my custom DomainServiceHost factory to host service.
3. Set debug points on overridable methods "ApplyConfigutation()" in CustomHost
Please find code for class used to injected service host factory at the end of this post.
4. Check where the code was failing and what RIA has configured before failing.Found that it have configured 3 endpoints for each service. Noticed the minimal configuration and rectified other errors one by one.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Ria.Services;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Description;
using System.ServiceModel.Channels;
using System.ComponentModel;
using System.Web.DomainServices;
using System.Net;
namespace System.Web.Ria {
public class DomainServiceHostFactoryEx : DomainServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
Uri baseAddress=null;
try
{
baseAddress = baseAddresses[0];
}
catch (Exception e)
{
baseAddress = new Uri("http://localhost:52878");
}
CustomHost customServiceHost =
new CustomHost(serviceType, baseAddress);
return customServiceHost;
}
}
class CustomHost : DomainServiceHost
{
DomainServiceDescription _domainServiceDescription;
ServiceDescription _sdecreption;
ContractDescription _contract;
public CustomHost(Type serviceType, params Uri[] baseAddresses)
: base(serviceType, baseAddresses)
{
this._domainServiceDescription = DomainServiceDescription.GetDescription(serviceType);
}
protected override ServiceDescription CreateDescription(out IDictionary<string, ContractDescription> implementedContracts)
{
ServiceDescription d = base.CreateDescription(out implementedContracts);
//_contract = implementedContracts[0];
_sdecreption = d;
return d;
}
protected override void ApplyConfiguration()
{
//base.LoadConfigurationSection(new System.ServiceModel.Configuration.ServiceElement(_sdecreption.ConfigurationName));
// try
//{
string error = "";
try
{
base.ApplyConfiguration();
}
catch (Exception applyconfigerror) { error += "Error1:" + applyconfigerror.Message + "\r\n"; }
try
{
//this.AddEndpoints();
}
catch (Exception applyconfigerror) { error += "Error2:" + applyconfigerror.Message + "\r\n"; }
try
{
// this.AddDefaultBehaviors();
}
catch (Exception applyconfigerror) { error += "Error3:" + applyconfigerror.Message + "\r\n"; }
//if (error.Length > 0) HttpContext.Current.AddError(new Exception( error));
//this.AddEndpoints();
//this.AddDefaultBehaviors();
using (IEnumerator<ServiceEndpoint> enumerator = base.Description.Endpoints.GetEnumerator())
{
while (enumerator.MoveNext())
{
ServiceEndpoint current = enumerator.Current;
//current.Binding.Scheme
}
}
//}
//catch (Exception ex)
// {
//HttpContext.Current.AddError(ex);
// }
}
}
}
Related posts
WCF RIA Service Hosting :: WCF RIA Service adding extra Required attribute on generated classes
We upgraded a Silverlight 3 RIA application to Silveright 4 bits. Once we fixed all the errors, it...
ASP.NET MVC 3 Hosting :: Introduction to ASP.NET MVC 3 Service Location
Introduction One of the new features in ASP.NET MVC 3 is the ability to register a service loca...
WCF Service Hosting :: Introduction to WCF Service
Introduction Asynchronous pattern is a very well known and common design pattern in systems that ...
ASP.NET Hosting
ASPHostCentral is a premier web hosting company where you will find low cost and reliable web hosting. We have supported the latest
ASP.NET 4.5 hosting
and
ASP.NET MVC 4 hosting
. We have supported the latest
SQL Server 2012 Hosting
,
SharePoint 2013 hosting
and
Windows Server 2012 Hosting
too!
Search
Include comments in search
Tag cloud
.net 4 hosting
.net 4.5 hosting
.net4 hosting
asp.net 4 hosting
asp.net 4.0 hosting
asp.net 4.5 hosting
asp.net mvc 3 hosting
asp.net mvc 3.0 hosting
asp.net mvc hosting
asp.net4 hosting
asphostcentral
asphostcentral.com
crystal report 2010 hosting
crystal report hosting
managed metadata
moss 2007 hosting
moss 2010 hosting
mssql 2008 r2 hosting
mvc 3 hosting
mvc 3.0 hosting
mvc hosting
sharepoint 2007 hosting
sharepoint 2010 hosting
sharepoint 3 hosting
sharepoint foundation 2010 hosting
sharepoint hosting
sharepoint server 2010 hosting
silverlight hosting
sp 2010 hosting
spf 2010 hosting
sql 2008 r2 hosting
wcf hosting
wss 2010 hosting
wss 3 hosting
wss hosting
Month List
2013
April (1)
January (3)
2012
December (4)
November (9)
October (3)
September (7)
August (1)
June (1)
March (7)
January (1)
2011
November (23)
October (15)
September (14)
August (2)
July (7)
June (2)
May (8)
April (7)
March (19)
February (2)
January (5)
2010
December (2)
November (8)
October (9)
September (10)
August (12)
July (4)
June (16)
May (4)
April (27)
March (4)
February (6)
January (5)
2009
November (4)
October (2)
August (2)
July (7)
June (1)
May (5)
April (7)
March (6)
February (13)
Other Hosting BLOG
ASPHostCentral.com
Reporting Service (SSRS) Hosting BLOG
ASP.NET MVC Hosting BLOG
Crystal Report Hosting BLOG
Sharepoint Hosting BLOG
Sharepoint 2010 Hosting BLOG
.NET4 Hosting BLOG
European ASP.NET 4.5 Hosting
ASPHostCentral.com REVIEW
ASPHostCentral.COM Twitter
Sharepoint Hosting NEWS
SQL 2008 R2 Hosting News
Silverlight WCF RIA Service Hosting News
ASP.NET 4.0 Hosting News
Sign in