WCF: Support for Wild Card Host Header at IIS 10 and above
IIS 10 came with new feature to support Wild Card Host Headers.
https://docs.microsoft.com/en-us/iis/get-started/whats-new-in-iis-10/wildcard-host-header-support
Does WCF support it?
WCF does not support this and still need to be configured in old way by creating multiple IIS binding for desired host headers.
Error we might see when browsing the WCF service:
The protocol binding 'X.X.X.X:80:*.XYZ.com' is not valid for 'http'. This might be because the port number is out of range.
Explanation:
WCF hosted on IIS internally calls ServiceHost class to initiate the service. Parameters needed to call it include URI object.
The below MSDN indicates that the URI object’s HOST property should always be DNS Host Name or IP Address.
https://msdn.microsoft.com/en-us/library/system.uri.host.aspx
If we use Wild Card Host header, eventually WCF will fail to initialize:
0:022> !DumpObj /d 0000019251191520
Name: System.UriBuilder
MethodTable: 00007ff94e851ad0
EEClass: 00007ff94e4c0520
Size: 96(0x60) bytes
File: C:\windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll
Fields:
MT Field Offset Type VT Attr Value Name
00007ff950c424b8 4000418 54 System.Boolean 1 instance 1 m_changed
00007ff950c716b8 4000419 8 System.String 0 instance 0000019051131420 m_fragment
00007ff950c716b8 400041a 10 System.String 0 instance 00000192511914c8 m_host
00007ff950c716b8 400041b 18 System.String 0 instance 0000019051131420 m_password
00007ff950c716b8 400041c 20 System.String 0 instance 0000019251191688 m_path
00007ff950c73e98 400041d 50 System.Int32 1 instance -1 m_port
00007ff950c716b8 400041e 28 System.String 0 instance 0000019051131420 m_query
00007ff950c716b8 400041f 30 System.String 0 instance 00000192511915d0 m_scheme
00007ff950c716b8 4000420 38 System.String 0 instance 00000192d113cfc0 m_schemeDelimiter
00007ff94e8a44e8 4000421 40 System.Uri 0 instance 0000000000000000 m_uri
00007ff950c716b8 4000422 48 System.String 0 instance 0000019051131420 m_username
0:022> !DumpObj /d 00000192511914c8
Name: System.String
MethodTable: 00007ff950c716b8
EEClass: 00007ff9505f47a8
Size: 56(0x38) bytes
File: C:\windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll
String: *.localhost.com
Fields:
MT Field Offset Type VT Attr Value Name
00007ff950c73e98 4000248 8 System.Int32 1 instance 15 m_stringLength
00007ff950c728c8 4000249 c System.Char 1 instance 2a m_firstChar
00007ff950c716b8 400024d 90 System.String 0 shared static Empty
>> Domain:Value 0000018f50912ee0:NotInit 00000193dc66d530:NotInit < !clrstack
OS Thread Id: 0x89c4 (22)
Child SP IP Call Site
0000000c2727e758 00007ff9648f3c58 [HelperMethodFrame: 0000000c2727e758]
0000000c2727e840 00007ff94ef40731 System.Uri.CreateThis(System.String, Boolean, System.UriKind)
0000000c2727e890 00007ff94e79184b System.UriBuilder.get_Uri()
0000000c2727e8d0 00007ff94d1c52d8 System.ServiceModel.Channels.BaseUriWithWildcard..ctor(System.String, Int32, System.String, Int32, System.String, System.String)
0000000c2727e940 00007ff94d1c57bd System.ServiceModel.Channels.BaseUriWithWildcard.CreateHostedUri(System.String, System.String, System.String)
0000000c2727e9b0 00007ff95ccf1960 System.ServiceModel.Activation.HttpHostedTransportConfiguration.CreateTransportManagers()
0:022> !DumpObj /d 0000019251193970
Name: System.String
MethodTable: 00007ff950c716b8
EEClass: 00007ff9505f47a8
Size: 118(0x76) bytes
File: C:\windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll
String: Invalid URI: The hostname could not be parsed.
Fields:
MT Field Offset Type VT Attr Value Name
00007ff950c73e98 4000248 8 System.Int32 1 instance 46 m_stringLength
00007ff950c728c8 4000249 c System.Char 1 instance 49 m_firstChar
00007ff950c716b8 400024d 90 System.String 0 shared static Empty
>> Domain:Value 0000018f50912ee0:NotInit 00000193dc66d530:NotInit <<
This is not purely a WCF API issue, rather this is a System.URI class usage issue which does not allow us to use wild card character. It only allows DNS Host Name or IP Address.
Hopefully this will be supported with WCF over new framework releases.
Thanks
Saurabh Somani