Click here to Skip to main content
13,350,483 members (63,681 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


18 bookmarked
Posted 27 Nov 2012

Access WCF Service Without Service Reference

, 27 Nov 2012
Rate this:
Please Sign up or sign in to vote.
Access a WCF Service without a service reference.
                                          Change is inevitable
This absolutely applies to Client Requirements, but not to our code . In other words, the above statement is one of the 3 design principles of Software architecture.
                                System should be Fault Tolerant.
This means, our system should be adoptable for changes and shouldn't break for every reasonable change.
Reason for bringing up this point is a recent situation i undergo.

I have my application consuming 4 WFC Services. And i need all 4 of them "Up and Running" all the time. In case of any failure i need to to intimated immediately. In simple words, i need a health monitoring system for all these services. Usually, i will create a system, which will consume these services via Service reference, and will invoke a method from each service and see if its responding or not.

Challenge: Service Reference
Yes, Service reference is the current challenge before us. Today, i have a set of services. May be tomorrow, all these services may be replaced by different services. Else couple of more services may got added. In both of the scenarios, i have to open my Heal monitoring system, and create service reference of new services.
This is a code change and it requires awful amount of time for testing the system.
You may think of generating a class file from wsdl using SVCUtil.exe, and then adding that class file in code. But it also required the code modification. Right?

Resolution: Access the WCF Service without service reference. 
This process is also called as "Dynamic Proxy Generation". While browsing for solution for my problem, i found a library written by a MSFT employee, which will take care of this. I would like to bring the same to your notice in this post.

1. Download the Project code attached in source.
2. Follow the steps mentioned below
3. Configure the services in config file and use the code snippet embedded below.
4. Have fun.

Source Code: Dynamic Proxy Library

1. Download code from above link. Look for "DynamicProxyLibrary"
2. Add the class library to your project. Change the Framework Version of the class library project to suite your actual project version. Else it will not allow you to refer the Project output.
3. Currently it is in 4.0 version. When you change the version, there are two 2 DLLs, which will go obsolete.
4. Remove the obsolete references and try adding those references from either GAC or from below path.
"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\(version)"
5. Once you are done with refrencing the above class library, use the below piece of code to create a dynamic proxy for the WCF service.
DynamicProxyFactory factory = 
new DynamicProxyFactory("http://localhost/Dependency1WCFSvc/DateService.svc?wsdl");
DynamicProxy proxy = factory.CreateProxy("IDateService");
var result = proxy.CallMethod("GetDate", null);
In order to generate a dynamic proxy, you need to have the url, name of the Contract. For ease of implementation, i haven't dealt with security stuff right now. We will see it in upcoming posts.

Task accomplished. We are able to access a WCF Service without service reference.

Is it helpful for you? Kindly let me know your comments / questions.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

You may also be interested in...


Comments and Discussions

QuestionClient certificate authentication Pin
dikahong7-Nov-16 19:13
memberdikahong7-Nov-16 19:13 
GeneralExcellent Perfect working 5 out of 5 :) Pin
darshan.pandya8612-Feb-14 20:12
memberdarshan.pandya8612-Feb-14 20:12 
QuestionCan not send any class type object Pin
Member 331555222-Oct-13 0:59
memberMember 331555222-Oct-13 0:59 
QuestionExelent Pin
Member 33155526-Aug-13 23:23
memberMember 33155526-Aug-13 23:23 
QuestionMaxReceivedMessageSize Pin
andreluizveras2-Jul-13 10:08
memberandreluizveras2-Jul-13 10:08 
GeneralMy vote of 5 Pin
whwqs16-May-13 21:06
memberwhwqs16-May-13 21:06 
Questionthis trick is not working, i getting an exception 'the associate <IContractName> endpoint address not found' Pin
Parag31222-Apr-13 1:34
memberParag31222-Apr-13 1:34 
Questionmark Pin
whwqs16-May-13 21:07
memberwhwqs16-May-13 21:07 
QuestionIn Silverlight? Pin
Member 842982927-Nov-12 22:37
memberMember 842982927-Nov-12 22:37 
GeneralMy vote of 4 Pin
Sperneder Patrick27-Nov-12 19:59
memberSperneder Patrick27-Nov-12 19:59 
QuestionCan't download Pin
Member 171879927-Nov-12 16:23
memberMember 171879927-Nov-12 16:23 
AnswerRe: Can't download Pin
PratapReddyP27-Nov-12 16:33
memberPratapReddyP27-Nov-12 16:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 27 Nov 2012
Article Copyright 2012 by PratapReddyP
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid