This print for content only-size & color not accurate 7" X 9-1/4" / casebound / malloy


// Open the host and start listening for incoming messages



Download 21,46 Mb.
Pdf ko'rish
bet1708/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   1704   1705   1706   1707   1708   1709   1710   1711   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

// Open the host and start listening for incoming messages.

serviceHost.Open();

// Keep the service running until the Enter key is pressed.

Console.WriteLine("The service is ready.");

Console.WriteLine("Press the Enter key to terminate service.");

Console.ReadLine();

}

}

If you now run this application, you will find that the host is alive in memory, ready to take



incoming requests from remote clients (see Figure 25-6).

Figure 25-6.

Our host, ready for external calls via basic HTTP binding 

Host Coding Options

Currently, we are creating our ServiceHost using a constructor that simply requires the service’s

type information. However, it is also possible to pass in an array of System.Uri types as a construc-

tor argument to represent the collection of addresses this service is accessible from. Currently, the

address is found via the *.config file; however, if we were to update the using scope as so:

using (ServiceHost serviceHost = new ServiceHost(typeof(MagicEightBallService),

new Uri[]{new Uri("http://localhost:8080/MagicEightBallService")}))

{

...



}

we would be able to define our endpoint as so:



binding="basicHttpBinding"

contract="MagicEightBallServiceLib.IEightBall"/>

Of course, too much hard-coding within a host’s code base decreases flexibility, so for the pur-

poses of this current host example, I’ll assume you are creating the service host simply by supplying

the type information as we did before:

using (ServiceHost serviceHost = new ServiceHost(typeof(MagicEightBallService)))

{

...



}

One of the (slightly frustrating) aspects of authoring host *.config files is that you have a num-

ber of ways to construct the XML descriptors, based on the amount of hard-coding you have in the

code base (as you have just seen in the case of the optional Uri array). To show yet another way to

author *.config files, consider the following reworking:

C H A P T E R   2 5  



I N T R O D U C I N G  W I N D O W S   C O M M U N I C AT I O N   F O U N D AT I O N



890

8849CH25.qxd  10/16/07  10:51 AM  Page 890














-->

binding="basicHttpBinding"

contract="MagicEightBallServiceLib.IEightBall"/>

















In this case, the address attribute of the  element is still empty, and regardless of the

fact that we are not specifying an array of Uri objects in code when creating the ServiceHost, the

application runs as before as the value is pulled from the baseAddresses scope. The benefit of stor-

ing the base address in a ’s  region is that other parts of a *.config file (such

as MEX, described shortly) also need to know the address of the service’s endpoint. Thus, rather

than having to copy and pass address values within a single *.config file, we can isolate the single

value as shown here.




Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   1704   1705   1706   1707   1708   1709   1710   1711   ...   1830




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2025
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish