December 2008 - Posts
Trying to configure WCF REST service hosted in IIS you may encounter an error message saying something like:
"The message with To '*' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher. Check that the sender and receiver's EndpointAddresses agree."
where '*' is the address you are trying to access. There are some answers here and there on the web but those are incomplete or hard to understand.
The Problem
When using the "*.svc" file to host a service within ASP.NET web site, regular WCF ServiceHost is created. WCF itself does not understand the REST address (as specified by the UriTemplate property of WebGet attribute), so we should configure the proper endpoint behavior "webHttp".
The Solution
So, here is how to configure WCF REST service to be hosted in IIS:
To host a service on IIS we are creating ".svc" file to map that file URL to the service type, for example:
<%@ ServiceHost Language="C#" Debug="true" Service="[ServiceFullTypeName]" %>
To enable this service as REST service, we will configure the required endpoint and behaviors in web.config:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="[ServiceTypeFullName]">
<endpoint address="js" binding="webHttpBinding" behaviorConfiguration="WebBehavior" contract="[ServiceContractName]"/>
</service>
</services>
</system.serviceModel>
Thats all!
Note that the "baseAddress" of this service is the URL to the ".svc" file, the "js" address is not required, but I prefer to distinguish between the "regular" address and the JSON address.
Recently, a programmer in my team, Amichai Sichel, had found a way to reset identity column in SQL Server DataBase. The reason he had to reset it was for testing and because of relations between tables he could not use TRUNCATE TABLE.
Assuming you want to clear your data, you first need to clean it with DELETE FROM [TableName], then you can RESEED it to any number you want, you need to RESEED it to the value before incrementing (if the column is specified a IDENTITY (1,1) which means its incremental is 1, you need to set it to the value you want minus 1)
DBCC CHECKIDENT('[TableName]', RESEED, 0) -- Will reseed it to 0 and the next identity will be 1 (assuming IDENTITY(1,1))
DBCC CHECKIDENT('[TableName]', NORESEED) -- Will not reseed the value and will return the maximum column value
for more information: http://technet.microsoft.com/en-us/library/ms176057.aspx
Thanks to Amichai Sichel
I wanted to share with you a strange behavior that I ran into today: ASP.NET web site that works on FireFox 2 (I assume it will work on 3 too), but it does not work on Internet Explorer!
I have disabled script debugging since I have FireBugs, as the web is full of JavaScript bugs and the popup message is annoying and also the line number that Internet Explorer reports on does not help at all.
After a little struggling I have found that the problem was an unnecessary colon (",") in JavaScript "class", like this:
function A(){}
A.prototype = {
funcA: function(a,b) { return a * b; },
funcB: function() { ... } , // <- Note this colon
};
This works great on FireFox (and FireBugs) but fails in Internet Explorer 7...
I had removed that colon and now it works great.