- Install the following two updates:
- Add a reference to "Microsoft.ServiceModel.DomainServices.Hosting" to your web application project
- Add the following to your web.config into the
tag <domainServices> <endpoints> <add name="OData" type="System.ServiceModel.DomainServices.Hosting.ODataEndpointFactory, System.ServiceModel.DomainServices.Hosting.OData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> <add name="Soap" type="Microsoft.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> <add name="Json" type="Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> endpoints> domainServices>
- Here the first pitfall arised; the application did not compile anymore complaining:
The "CreateRiaClientFilesTask" task failed unexpectedly.
Unrecognized configuration section system.serviceModel/domainServices.
To resolve this add the following to thetag: <sectionGroup name="system.serviceModel"> <section name="domainServices" type="System.ServiceModel.DomainServices.Hosting.DomainServicesSection, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" allowDefinition="MachineToApplication" requirePermission="false" /> sectionGroup>
- According to some howtos the URL is composed as follows:
http://localhost:[port]/[Name of Silverlight Project]-Web-[Name of Webservice]/Json/[Method name]
e.g.: http://localhost:2002/MySilverlightApp-Web-DataAccessService/Json/GetArticles - The above URL always returned 404 Not found
- My next pitfall was that my service class file was not in the web project but in a subfolder ("Services") of it
- To solve that I had to modify the URL as follows:
http://localhost:[port]/[Name of Silverlight Project]-Web-[Folder name]-[Name of Webservice]/Json/[Method name]
e.g.: http://localhost:2002/MySilverlightApp-Web-Services-DataAccessService/Json/GetArticles - After that I finally got my JSON from my webservice :-)
Manfred's Blog
Blog about computer, software and programming.
Wednesday, April 11, 2012
WCF RIA Services with JSON endpoint
Monday, March 12, 2012
Entity Framework no columns when mapping stored procedure
After some research I found out that in some circumstances it is necessary to add the following two statements at the beginning of the stored procedure:
SET NOCOUNT OFF; SET FMTONLY OFF;
After that everything worked as expected.
Wednesday, March 9, 2011
New version of Team Viewer
Link to Team Viewer
Monday, November 29, 2010
Smelly code
public bool isLocked(string s)
{
if (!File.Exists(s)) return false;
try { FileStream f = File.Open(s, FileMode.Open, FileAccess.ReadWrite); f.Close(); }
catch { return true; }
return false;
}Objections and Comments
The code abve has in my eyes several problems:
- Method name starts with lower case
- The name of the input parameter is meaningless
- Logical code blocks are not separated by a new line
- You need some time to understand what this 4 lines of code do
- Multiple instructions on the same line
- The "return false;" statement should be inside the try block because it is logically associated to it
- Missing Method documentation
Proposed Refactoring
/// <summary>
/// Checks if a file is in use or not.
/// </summary>
/// <param name="filePath">The path to the file that should be checked.</param>
/// <returns>True if the file is locked; false otherwise</returns>
public bool IsLocked(string filePath)
{
if (!File.Exists(filePath))
{
return false;
}
try
{
FileStream fileStream = File.Open(filePath, FileMode.Open, FileAccess.ReadWrite);
fileStream.Close();
return false;
}
catch
{
return true;
}
}
Monday, July 19, 2010
Strange undestroyable folders
A friend of mine had a very very strange problem. Suddenly on his external hard disk there appeared a bunch of very strangely named folders like "%/sl94..." and other symbols which windows was not able to display. They occupied 300GB and clearly my friend wanted to delete them; unfortunately windows was not able to delete them. It gave always an error like "Path not found" or "Invalid path symbols".
I tried then to delete them with different data shredders but none of them was able to successfully delete them.
I have then run also different virus and spy-ware scanners over them but none of them found something.
I was stuck and at the end with my knowledge.
Then I found on the Internet the good old command line instruction:
del foldername
With that I was finally able to delete them all.
Direct SQL vs. View vs. Stored Procedure
I was wondering for a very very long time what all these "battels" around direct sql, views and stored procedures are about. I read several articles on the Internet where people were claiming that nowadays there is almost no difference anymore between these three database "constructs". I saw many discussions and blogs where people tested the performance of these three with different results and that made me even more confused.
So as I am curious and the fact that I need to know this as a software developer I decided to try this out by myself. At work I had the chance to test this against a very large amount of real data (I needed to optimize this query anyway);
Sometimes the sample databases which are used for theses kinds of tests are either very small or very simple or even both which makes not really sense in my eyes.
So the query consisted of joins of multiple tables with a case in the select statement. I run the query 300 times with every "construct" and then I took the average value for all three of them in order to reduce network and SQL Server workload "noise".
The result of my test (in Ticks):
Direct SQL | 23077 |
View | 19363 |
Stored procedure | 3438 |
So what I found out for myself is that it really does matter what kind of "construct" you use to query your data; especially on a large amount of data.
On large data you should also take into consideration that a big performance impact may also have where you set your indexes and which statistical data you let create by SQL Server.
If you made other experiences on this, please let me know and leave a comment...
Executing SQLQueries on ObjectContext
Recently I worked with the entity framework (3.5) and at some point I had the need to execute a custom SQL command. Fortunately does the object context provide the underlying DBConnection and with that you can simply execute SQLCommands.
I read on the Internet that the new Version (4.0) has already integrated something similar.
This is an extension Method that I wrote which makes it easy to execute these queries:
public static void ExecuteSQL(this ObjectContext context, string sql)
{
var connection = context.Connection;
var command = connection.CreateCommand();
command.CommandText = sql;
try
{
connection.Open();
command.ExecuteNonQuery();
}
finally
{
connection.Close();
}
}