HOWTO: Fix WCF Host Name on IIS
By gavinmckay
This is a problem I have tripped across before, and it just popped up again. Time for a post on how to fix it, mainly so I won’t have to track down MSDN articles and obscure posts to remember how to do it!
When building a WCF Web Service on your local machine, the service will automatically generate WSDL for you with an address similar to http://YOURPC/MyService.svc. This works fine when testing locally, but when you want to publish this to your production environment so it can be used by World + Dog, it doesn’t respect the fact you have a nice URL you would like to use instead. For example, if your production server is “Server01″ and the URL you have assigned to the website in IIS is my.publicserver.com, your service may look like this:
Instead of displaying the “real” URL (my.publicserver.com), it displays the name of the server (server01) instead. Not at all what is required! Worse still, connections to your web server will fail because the WSDL is pointing to the non-published server name and your client won’t be able to get there. This is because WCF automatically uses the IIS Site Bindings to determine what the base addresses for the service should be.
The solution is to update the IIS metabase so IIS knows what to do with the request, then WCF will pick up on this. To fix this, perform the following steps.
Get the Website Identifier from IIS
To change the site bindings you need to know which site to change. Open the IIS Manager to view the sites available, find the one you want to change, and record the website id in the “Identifier” column. You will need this in the next step.
.....
Copied from gavin mckey blog
Just a log of stuff that I've usually forget, with comical spin. On my way to get organized ...
24 December 2010
The page you are requesting cannot be served because of the extension configuration
Recently, I migrated to Windows 7 and ended up installing all my software's again. I had a project which involved hosting a WCF service on IIS. The service used a .svc file extension and IIS 7 on my machine was not aware how to handle these files.
The error I got looked something like this:
HTTP Error 404.3 – Not Found
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map. Detailed Error InformationModule StaticFileModule.
There were more errors related to local machine below these errors.I looked up the net and after some digging figured out the solution to the problem:
Run Visual Studio 2008 Command Prompt as “Administrator”.
Navigate to C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation.
Run this command servicemodelreg –i.
The servicemodelreg is a command line tool which provides the ability to manage the registration on ServiceModel on a machine. You can get more info on the tool at MSDN here.
I guess the mistake I made was enabling IIS post installing VS and .NET 3.5 or else the services are not turned on for IIS 7.0 by default.
Copied from Rahul's blog
The error I got looked something like this:
HTTP Error 404.3 – Not Found
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map. Detailed Error InformationModule StaticFileModule.
There were more errors related to local machine below these errors.I looked up the net and after some digging figured out the solution to the problem:
Run Visual Studio 2008 Command Prompt as “Administrator”.
Navigate to C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation.
Run this command servicemodelreg –i.
The servicemodelreg is a command line tool which provides the ability to manage the registration on ServiceModel on a machine. You can get more info on the tool at MSDN here.
I guess the mistake I made was enabling IIS post installing VS and .NET 3.5 or else the services are not turned on for IIS 7.0 by default.
Copied from Rahul's blog
15 November 2010
syntax for adding dll to gac and forcing reinstall
[directory where dll is located][directory where gacutil is located]\gacutil /i [dll full name]/f
23 June 2010
jQuery's ajax request by POST method cause the security validation error
To avoid security validation error:
- First you need to make sure that your web.config file is updated to support Ajax.Net. In turn that will enable you to use ajax calls with json parameters. There are a lot of changes there, so be careful.
- Use Fidler to see the actual request/response, this may shed some more light on the matter
- Make sure GetDataMethod is a static
- Make sure 'data' is a valid jason object passed as a string
- Make sure 'dataType' is 'json', assuming you updated the web.config
- Make sure 'contentType' is 'application/json; charset=utf-8'
Finally, the proper ajax POST format is like so:
$.ajax({
'type' : 'POST',
'url' : 'GetSampleData.aspx/GetDataMethod',
'data' : '{data:"abcdfg"}',
'contentType': 'application/json; charset=utf-8',
'dataType' : 'json',
'success' : function (data) {
//process data
},
'error' : function (xhttp, textStatus, errorThrown) {
//show error
}
});
- Use Fidler to see the actual request/response, this may shed some more light on the matter
- Make sure GetDataMethod is a static
- Make sure 'data' is a valid jason object passed as a string
- Make sure 'dataType' is 'json', assuming you updated the web.config
- Make sure 'contentType' is 'application/json; charset=utf-8'
Finally, the proper ajax POST format is like so:
$.ajax({
'type' : 'POST',
'url' : 'GetSampleData.aspx/GetDataMethod',
'data' : '{data:"abcdfg"}',
'contentType': 'application/json; charset=utf-8',
'dataType' : 'json',
'success' : function (data) {
//process data
},
'error' : function (xhttp, textStatus, errorThrown) {
//show error
}
});
18 February 2010
Migrating IIS from one server to another ...
I had to move IIS server from server A to server B and was faced with lengthy task of manually creating all virtual directories ...
Then I thought that there must be easier way to handle that and there it was
Link to source "Migrating IIS"
To summarize it basically includes following steps:
Then I thought that there must be easier way to handle that and there it was
Link to source "Migrating IIS"
To summarize it basically includes following steps:
- Create back up on IIS server A (with password)
- Grab the backup from following location: ..\system32\inetsrv\metaback
- Copy backup to server B on the same location ..\system32\inetsrv\metaback
- Run restore on IIS server B pointing to created backup
- When IIS ask for password provide it and that's it :-)
17 February 2010
How to transfer the logins and the passwords between instances of SQL Servers ...
Here is a short explanation about how to move logins between instances of sql servers
- Create store procedure
- Execute following store procedure: EXEC sp_help_revlogin
USE master
GO
IF OBJECT_ID ('sp_hexadecimal') IS NOT NULL
DROP PROCEDURE sp_hexadecimal
GO
CREATE PROCEDURE sp_hexadecimal
@binvalue varbinary(256),
@hexvalue varchar (514) OUTPUT
AS
DECLARE @charvalue varchar (514)
DECLARE @i int
DECLARE @length int
DECLARE @hexstring char(16)
SELECT @charvalue = '0x'
SELECT @i = 1
SELECT @length = DATALENGTH (@binvalue)
SELECT @hexstring = '0123456789ABCDEF'
WHILE (@i <= @length) BEGIN DECLARE @tempint int DECLARE @firstint int DECLARE @secondint int SELECT @tempint = CONVERT(int, SUBSTRING(@binvalue,@i,1)) SELECT @firstint = FLOOR(@tempint/16) SELECT @secondint = @tempint - (@firstint*16) SELECT @charvalue = @charvalue + SUBSTRING(@hexstring, @firstint+1, 1) + SUBSTRING(@hexstring, @secondint+1, 1) SELECT @i = @i + 1 END SELECT @hexvalue = @charvalue GO IF OBJECT_ID ('sp_help_revlogin') IS NOT NULL DROP PROCEDURE sp_help_revlogin GO CREATE PROCEDURE sp_help_revlogin @login_name sysname = NULL AS DECLARE @name sysname DECLARE @type varchar (1) DECLARE @hasaccess int DECLARE @denylogin int DECLARE @is_disabled int DECLARE @PWD_varbinary varbinary (256) DECLARE @PWD_string varchar (514) DECLARE @SID_varbinary varbinary (85) DECLARE @SID_string varchar (514) DECLARE @tmpstr varchar (1024) DECLARE @is_policy_checked varchar (3) DECLARE @is_expiration_checked varchar (3) DECLARE @defaultdb sysname IF (@login_name IS NULL) DECLARE login_curs CURSOR FOR SELECT p.sid, p.name, p.type, p.is_disabled, p.default_database_name, l.hasaccess, l.denylogin FROM sys.server_principals p LEFT JOIN sys.syslogins l ON ( l.name = p.name ) WHERE p.type IN ( 'S', 'G', 'U' ) AND p.name <> 'sa'
ELSE
DECLARE login_curs CURSOR FOR
SELECT p.sid, p.name, p.type, p.is_disabled, p.default_database_name, l.hasaccess, l.denylogin FROM
sys.server_principals p LEFT JOIN sys.syslogins l
ON ( l.name = p.name ) WHERE p.type IN ( 'S', 'G', 'U' ) AND p.name = @login_name
OPEN login_curs
FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @type, @is_disabled, @defaultdb, @hasaccess, @denylogin
IF (@@fetch_status = -1)
BEGIN
PRINT 'No login(s) found.'
CLOSE login_curs
DEALLOCATE login_curs
RETURN -1
END
SET @tmpstr = '/* sp_help_revlogin script '
PRINT @tmpstr
SET @tmpstr = '** Generated ' + CONVERT (varchar, GETDATE()) + ' on ' + @@SERVERNAME + ' */'
PRINT @tmpstr
PRINT ''
WHILE (@@fetch_status <> -1)
BEGIN
IF (@@fetch_status <> -2)
BEGIN
PRINT ''
SET @tmpstr = '-- Login: ' + @name
PRINT @tmpstr
IF (@type IN ( 'G', 'U'))
BEGIN -- NT authenticated account/group
SET @tmpstr = 'CREATE LOGIN ' + QUOTENAME( @name ) + ' FROM WINDOWS WITH DEFAULT_DATABASE = [' + @defaultdb + ']'
END
ELSE BEGIN -- SQL Server authentication
-- obtain password and sid
SET @PWD_varbinary = CAST( LOGINPROPERTY( @name, 'PasswordHash' ) AS varbinary (256) )
EXEC sp_hexadecimal @PWD_varbinary, @PWD_string OUT
EXEC sp_hexadecimal @SID_varbinary,@SID_string OUT
-- obtain password policy state
SELECT @is_policy_checked = CASE is_policy_checked WHEN 1 THEN 'ON' WHEN 0 THEN 'OFF' ELSE NULL END FROM sys.sql_logins WHERE name = @name
SELECT @is_expiration_checked = CASE is_expiration_checked WHEN 1 THEN 'ON' WHEN 0 THEN 'OFF' ELSE NULL END FROM sys.sql_logins WHERE name = @name
SET @tmpstr = 'CREATE LOGIN ' + QUOTENAME( @name ) + ' WITH PASSWORD = ' + @PWD_string + ' HASHED, SID = ' + @SID_string + ', DEFAULT_DATABASE = [' + @defaultdb + ']'
IF ( @is_policy_checked IS NOT NULL )
BEGIN
SET @tmpstr = @tmpstr + ', CHECK_POLICY = ' + @is_policy_checked
END
IF ( @is_expiration_checked IS NOT NULL )
BEGIN
SET @tmpstr = @tmpstr + ', CHECK_EXPIRATION = ' + @is_expiration_checked
END
END
IF (@denylogin = 1)
BEGIN -- login is denied access
SET @tmpstr = @tmpstr + '; DENY CONNECT SQL TO ' + QUOTENAME( @name )
END
ELSE IF (@hasaccess = 0)
BEGIN -- login exists but does not have access
SET @tmpstr = @tmpstr + '; REVOKE CONNECT SQL TO ' + QUOTENAME( @name )
END
IF (@is_disabled = 1)
BEGIN -- login is disabled
SET @tmpstr = @tmpstr + '; ALTER LOGIN ' + QUOTENAME( @name ) + ' DISABLE'
END
PRINT @tmpstr
END
FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @type, @is_disabled, @defaultdb, @hasaccess, @denylogin
END
CLOSE login_curs
DEALLOCATE login_curs
RETURN 0
Subscribe to:
Posts (Atom)