Hi friends,
In this article i will tell you how to call WCF
service without creating service reference
Sometimes we need to calling service without adding
service reference.
The ChannelFactory object is used to create a communication channel
with the service. Note that the BasicHttpBinding is used (because it was
used in configuration of the service's host) and the same URL address
The
used ChannelFactory object is created for the service's interface and is able to create an object implementing this interface
which can be easily used in the code
Following steps are required for creating channelFactory
Step 1 : Initialize Channel factory
Step 2 : create channel factory
Step 3 : Access Proxy
Example :
Let Assume that your service name is ConfigurationServices and it has method getCustomerDetails.
we retrieve User Details based on UserId using getCustomerDetails method.
Below is the code snippet.
var
factory = new ChannelFactory<ConfigurationServices>(new
BasicHttpBinding(),
new
EndpointAddress("http://localhost/HirenWebServices/ConfigurationServices"));
var
proxy = factory.CreateChannel();
var
response = proxy.getCustomerDetails(
new getCustomerDetails() { arg0 =
AppConfiguration.Current.Userid });
var
v = response.@return;
Happy Programming!!
Don’t forget to leave your feedback
and comments below!
If you have any query mail me to Sujeet.bhujbal@gmail.com
Regards
Sujeet Bhujbal
--------------------------------------------------------------------------------
Personal Website :-http://sujitbhujbal.wordpress.com/
Facebook :-www.facebook.com/sujit.bhujbal
CodeProject:-http://www.codeproject.com/Members/Sujit-Bhujbal
Linkedin :-http://in.linkedin.com/in/sujitbhujbal
Stack-Exchange: http://stackexchange.com/users/469811/sujit-bhujbal
Twitter :-http://twitter.com/SujeetBhujbal
JavaTalks :-http://www.javatalks.com/Blogger/sujit9923/
-----------------------------------------------------------------------------------
Your nice work is very attractive and impressive.
ReplyDelete1337x UK proxy
This is so essential post. This information helps them who are new bloggers. Thanks for helpful post for us.
ReplyDeleteMp3Juices UK proxy