Showing posts with label SaaS. Show all posts
Showing posts with label SaaS. Show all posts

Wednesday, January 02, 2013

WCF Error: The service cannot be activated because it does not support ASP.NET compatibility.

Hi Folks,

I was developing a secure WCF service that allows only authenticated windows users to access this service in IIS 7.5. After disabling the anonymous access i figured that wsHttpBinding will not work because you have to enable it to make the WCF binding working, then i changed the WCF binding to basicHttpBinding and passed the user credentials from the web application by using below line of code:

C# Code:
svc.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;

The above line passed the user credentials from the client web application to the service.

Passing the credentials from the client web application wasn't accepted by the WCF service because i was getting another error message from the wcf service:

"The underlying provider failed on Open WCF when hosting in IIS with impersonation is enabled"

Since i have enabled the impersonation to pass the user credentials from the web application to the wcf i was missing the step to add the following configuration in the web.config of the WCF service:

<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>

"The default is false. When this attribute is set to true, requests to Windows Communication Foundation (WCF) services flow through the ASP.NET HTTP pipeline, and communication over non-HTTP protocols is prohibited"

One last thing you should add in the service class "aspNetCompatibilityEnabled" attribute to comply with configuration entry otherwise still your service won't work because it will use the default IIS account to access your database.

C# Code:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class myService : ImyService
// your implementation to the service.
}


Hope this helps!

References:

1) WCF serviceHostingEnvironment element:
http://msdn.microsoft.com/en-us/library/ms731336(v=VS.110).aspx



Tuesday, March 08, 2011

How to calculate SQL Azure Storage per client in your DB ?

Hi All,
If you have a cloud based solution hosted in Windows Azure and you are using SQL Azure Database as a backend database. You will need to think about how much storage each client who is going to use your solution will consume from DB storage you have in the cloud. This concept is essential since the concept behind Software As A Service aka (SaaS) is to pay as you go. So, the client pays only for the storage he takes in the cloud and this is a competitive advantage you should give when you sell cloud based solutions.

Since you have a backend database that has all your clients data, You need to give the storage that has been taken by each client in your database. To do this, I was thinking that if i can get the Database size in MB and the size of each table.
I'd be able to calculate the storage for each client.

For example: If i have a table in my DB called Client, and set of tables Table1,Table2...etc.To get the total DB size in MB in SQL Azure, please check this command:

-- Calculates the size of the database.   
SELECT SUM(reserved_page_count)*8.0/1024  FROM sys.dm_db_partition_stats;   
GO

To get the size for each table, here is how to get the size of each table in SQL Azure:
-- Calculates the size of individual database objects.   
SELECT sys.objects.name, SUM(reserved_page_count) * 8.0 / 1024  
FROM sys.dm_db_partition_stats, sys.objects   
WHERE sys.dm_db_partition_stats.object_id = sys.objects.object_id   GROUP BY sys.objects.name; GO
So if i get the number of records in Table1 for client 1, So the storage that has been used in table1 by client 1 is equal to =Total Table Size * ( Client Records / Total Records ) 

Same will be calculated for all other tables.

The total amount of storage for client 1 is the summation Storage by client 1 for each table.
So you can show this amount in your interface under your system admin module and will be able to charge each customer on monthly basis for example.

Another question : What about the synchronization feature for cloud data in DBs ? You can either back up the database on periodic basis or do data sync in SQL Azure. Read more about SQL Azure Sync. framework:
http://archive.msdn.microsoft.com/sync/Release/ProjectReleases.aspx?ReleaseId=5037

Hope this Helps, Please post here any questions if something came across your mind ?
Thanks.

References:
- Monitoring SQL Azure Dynamic Management Views:




Regards,
Mostafa Arafa
twitter.com/mostafaelzoghbi