Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Remarks

Using Lhe HLLpLisLener class, you can creaLe a simple H11P proLocol lisLener LhaL responds Lo H11P
requesLs. 1he lisLener is acLive or Lhe lieLime o Lhe HLLpLisLener objecL and runs wiLhin your applicaLion
wiLh iLs permissions.
Note
1his class is available only on compuLers running Lhe Windows XP SP2 or Windows Server 2003 operaLing
sysLems. l you aLLempL Lo creaLe an HLLpLisLener objecL on a compuLer LhaL is running an earlier operaLing
sysLem, Lhe consLrucLor Lhrows a PlaLormNoLSupporLedFxcepLion excepLion.
1o use HLLpLisLener, creaLe a new insLance o Lhe class using Lhe HLLpLisLener consLrucLor and use Lhe
Preixes properLy Lo gain access Lo Lhe collecLion LhaL holds Lhe sLrings LhaL speciy which Uniorm Resource
ldenLiier (URl) preixes Lhe HLLpLisLener should process.
A URl preix sLring is composed o a scheme (hLLp or hLLps), a hosL, an opLional porL, and an opLional paLh.
An example o a compleLe preix sLring is "hLLp.//www.conLoso.com.8080/cusLomerDaLa/". Prefixes must
end in a forward sIash ("/"). 1he HLLpLisLener objecL wiLh Lhe preix LhaL mosL closely maLches a requesLed
URl responds Lo Lhe requesL. MulLiple HLLpLisLener objecLs cannoL add Lhe same preix, a Win32FxcepLion
excepLion is Lhrown i an HLLpLisLener adds a preix LhaL is already in use.
When a porL is speciied, Lhe hosL elemenL can be replaced wiLh "*" Lo indicaLe LhaL Lhe HLLpLisLener accepLs
requesLs senL Lo Lhe porL i Lhe requesLed URl does noL maLch any oLher preix. For example, Lo receive all
requesLs senL Lo porL 8080 when Lhe requesLed URl is noL handled by any HLLpLisLener, Lhe preix is
"hLLp.//*.8080/". Similarly, Lo speciy LhaL Lhe HLLpLisLener accepLs all requesLs senL Lo a porL, replace Lhe
hosL elemenL wiLh Lhe "-" characLer, "hLLps.//-.8080". 1he "*" and "-" characLers can be presenL in preixes
LhaL include paLhs.
1o begin lisLening or requesLs rom clienLs, add Lhe URl preixes Lo Lhe collecLion and call Lhe SLarL meLhod.
HLLpLisLener oers boLh synchronous and asynchronous models or processing clienL requesLs. RequesLs
and Lheir associaLed responses are accessed using Lhe HLLpLisLenerConLexL objecL reLurned by Lhe
CeLConLexL meLhod or iLs asynchronous counLerparLs, Lhe 8eginCeLConLexL and FndCeLConLexL meLhods.
1he synchronous model is appropriaLe i your applicaLion should block while waiLing or a clienL requesL
and i you wanL Lo process only one requesL aL a Lime. Using Lhe synchronous model, call Lhe CeLConLexL
meLhod, which waiLs or a clienL Lo send a requesL. 1he meLhod reLurns an HLLpLisLenerConLexL objecL Lo
you or processing when one occurs.
ln Lhe more complex asynchronous model, your applicaLion does noL block while waiLing or requesLs and
each requesL is processed in iLs own execuLion Lhread. Use Lhe 8eginCeLConLexL meLhod Lo speciy an
applicaLion-deined meLhod Lo be called or each incoming requesL. WiLhin LhaL meLhod, call Lhe
FndCeLConLexL meLhod Lo obLain Lhe requesL, process iL, and respond.
ln eiLher model, incoming requesLs are accessed using Lhe HLLpLisLenerConLexL.RequesL properLy and are
represenLed by HLLpLisLenerRequesL objecLs. Similarly, responses are accessed using Lhe
HLLpLisLenerConLexL.Response properLy and are represenLed by HLLpLisLenerResponse objecLs. 1hese
objecLs share some uncLionaliLy wiLh Lhe HLLpWebRequesL and HLLpWebResponse objecLs, buL Lhe laLLer
objecLs cannoL be used in conjuncLion wiLh HLLpLisLener because Lhey implemenL clienL, noL server,
behaviors.
An HLLpLisLener can require clienL auLhenLicaLion. ou can eiLher speciy a parLicular scheme Lo use or
auLhenLicaLion, or you can speciy a delegaLe LhaL deLermines Lhe scheme Lo use. ou musL require some
orm o auLhenLicaLion Lo obLain inormaLion abouL Lhe clienL's idenLiLy. For addiLional inormaLion, see Lhe
User, AuLhenLicaLionSchemes, and AuLhenLicaLionSchemeSelecLorDelegaLe properLies.
Note
l you creaLe an HLLpLisLener using hLLps, you musL selecL a Server CerLiicaLe or LhaL lisLener. OLherwise, an
HLLpWebRequesL query o Lhis HLLpLisLener will ail wiLh an unexpecLed close o Lhe connecLion.
Note
ou can conigure Server CerLiicaLes and oLher lisLener opLions by using HLLpCg.exe. See
hLLp.//msdn.microsoL.com/library/deaulL.aspurl=/library/en-us/hLLp/hLLp/hLLpcg_exe.asp or more
deLails. 1he execuLable is shipped wiLh Windows Server 2003, or can be builL rom source code available in
Lhe PlaLorm SDK.
Note
l you speciy mulLiple auLhenLicaLion schemes or Lhe HLLpLisLener, Lhe lisLener will challenge clienLs in Lhe
ollowing order. NegoLiaLe, N1LM, DigesL, and Lhen 8asic.
windows 5erver 2003 PIatform Note. ls required Lo use Lhis class.

You might also like