-Balaji Ramasamy
As I
was working on project, it demanded to run the WCF service during
development which was a challenging task for a novice developer. We
successfully developed the WCF service by implementing the service
contract interface & service behavior class. The above developed
WCF service needs to be consumed by the client application, which
will interact with the end point of the services and provides the
requested response. To successfully build and test the application,
the WCF service needs to be exposed, which will be consumed by client
application with the help of svcutil tool. Since the WCF service is a
class library, we can’t run it as service.
So
here comes the question of how to run the WCF service to generate and
consume the service proxy in my client windows application during
development. We are very much aware of hosting the service via the
console application, winforms application, windows service, IIS, WAS
to host the WCF service. Initially we ran the WCF service as windows
service, assuming it as a right decision, which resulted in multiple
installation and un-installation of windows service. To avoid such
painful process during development, we planned to run the WCF service
in console application. But how to run in console application? Here
comes the ServiceHost runtime, which will enable to the WCF service
to load the service class, set up the endpoints and channel
listeners, which provides your service class an “ecosystem” to
live and operate in.
You
can either instantiate a ServiceHost class yourself in a console app,
a Windows service, or even a Winforms app, and thus make your WCF
service class available to the outside world - or you can delegate
that work to IIS or WAS. Even IIS or WAS will use a ServiceHost to
host your WCF service - they just do it automatically behind the
scenes.
The
following is the console application code to run the WCF service
internal
class
Program
{
private
static
void
Main(string[]
args)
{
try
{
StartService();
Console.WriteLine("Service
is running...");
Console.WriteLine("Press
key to end...");
Console.ReadLine();
StopService();
}
catch
(Exception
ex)
{
//Log
the Exception
}
}
internal
static
ServiceHost
myServiceHost = null;
internal
static
void
StartService()
{
try
{
myServiceHost
= new
ServiceHost(typeof([namespaceName.ServiceBehaviourClassName]));
myServiceHost.Open();
}
catch
(Exception
ex)
{
//Log
the Exception
}
}
internal
static
void
StopService()
{
try
{
if
(myServiceHost.State != CommunicationState.Closed)
myServiceHost.Close();
}
catch
(Exception
ex)
{
//Log
the Exception
}
}
}
And the Application
configuration includes be the following
<system.serviceModel>
<services>
<service
name="[namespaceName.ServiceBehaviourClassName]"
behaviorConfiguration="metadataSupport">
<host>
<baseAddresses>
<add
baseAddress="[EndPoint
Address]"
/>
</baseAddresses>
</host>
<endpoint
address=""
binding="[Binding
Name]"
contract="[namespaceName.ServiceContractName]"
"/>
<endpoint
address="mex"
binding="mexNamedPipeBinding"
contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior
name="metadataSupport">
<serviceMetadata
/>
<serviceDebug
includeExceptionDetailInFaults="true"
/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Note: Application
Configuration may vary from one binding to another binding. Please
check Microsoft MSDN site for more details about bindings and its
related configuration
Now run the service and
its ready to consume in the client application during development
stage of our application
References:
19 comments:
thanks for post.
Website design London
Found your content extremely outstanding. It is definitely useful for every developer working on some specific project.
It will be great idea for college students to visit this website. Here you can learn how to write annotated bibliography
For any type of coursework help, you can hire experts from StudentsAssignmentHelp.com. Students can buy coursework New Zealand help instantly and get free revisions. You can query with our experts by 24*7 online customer support.
Our website AllAssignmenthelp.com which is associated with different nation’s site moreover. We give our administration everywhere throughout the world. Our assignment help is given to all through the students.
Java Assignment Help
Your information is very detailed and useful to me, thank you for sharing. We provide affordable Assignment Help in Australia. Assignment Help Sydney
“Write my speech for me.” How many times have you been asking yourself such questions? Luckily, you have an outstanding opportunity to approach speech writing company by clicking on the link.
Hello guys it is quite importnat to graduate from the university with the good diploma and in order to do so you should prepare for the sbjects and your courseworks good essays, which will allow you to get the good mark. Moreover I understand how it is difficult for some students to write a good essay especially on the first year of studiyng but know you can easily cope with this task just only buying college essays and get such esaays very qualified and exclusive one and also disocver how do you spell speech
A huge thanks to https://grademiners.com/ service for their amazing performance. I was a bit anxious about the volume of work and that the writer might not be able to complete it all on time, despite all the assurances. So I was thrilled to find my research paper ready for print this morning! Amazing!
Hello! I want to share a useful site where you can find topics for your essays. See https://essays-writer.net/health-care-research-topics-for-argumentative-essay-best-ideas.html. I am sure you will find something to write your paper about.
Thanks for sharing the informative post about.
I have learned many new information from your post.If You want to play online mobile game.
Visit now Game Development Kolkata
Game Development Company in Kolkata,
Kolkata Game Developers,
Game development Kolkata,
List of Game Design Courses,
mobile game development company in india,
Game development company in India
Game Development Kolkata
https://www.gowebs.in/game-development-kolkata
Other Services :
web design in Kolkata
https://www.gowebs.in/web-design-kolkata
web design Howrah
https://www.gowebs.in/website-design-in-howrah
web design Baripada
https://www.gowebs.in/web-design-Baripada
I really enjoyed reading this post, it’s really informative and great.
Website Design in Baripada (M), Mayurbhanj, Orissa - Rs999
Website Design in Baripada (M), Mayurbhanj, Orissa - Rs999
https://www.gowebs.in/web-design-Baripada
Obviously, your post extremely good After reading this post. Keep it up
Top 50 Web Designers in Baripada Bazar, Mayurbhanj
Website Design in Baripada (M), Mayurbhanj, Orissa - Rs999,
Web Design Service in Baripada,
Best Logo Design Company in Baripada,
Website Design Cost in Baripada,
Top 50 Web Designers in Baripada Bazar, Mayurbhanj
website design baripada
website design baripada
https://www.gowebs.in/web-design-Baripada
This is extremely helpful info!! Very good work.
Satta Matka Game Software Development
Satta Matka Game Software Development
https://www.gowebs.in/satta-matka-software-development
Submitting an essay is coming soon and you don't know what to do? Having trouble writing? Not sure on what topic to write your essay work? I think you should take advantage of this https://primeessay.org/how-to-write-newspaper-article.html and pass your work perfectly!
To develop different projects, you need to have a good understanding of the whole system, plan and consequences.
We are writers, we must understand writing well and write correctly.
We are also approached by many professional people who need help with written assignments.
We will tell you how to write a lab report and many other tasks. We write qualitatively and sparingly. At a low price
Great tips. Thank you for sharing it. If you want to buy lab reports online, refer to me. I have a great experience working with professional writers. I can assist with recommendations.
Reliable Marketing help service: Myassignmenthelp.com is the most trusted marketing assignment help service providers. Students trust us for many reasons. We provide the best service quality at the most cost-efficient price
Post a Comment