Click here to Skip to main content
13,092,310 members (60,552 online)
Click here to Skip to main content
Add your own
alternative version


2 bookmarked
Posted 8 Apr 2013

Generate interface for WebService client stub by using CodeDom

, 8 Apr 2013
Rate this:
Please Sign up or sign in to vote.
Generate interface for WebService client stub for unit testing.


This is a simple application that generate the interface for the WebService client stub.


What the generated interface can do ? Em... Because the all methods of the WebService client stub are not virtual. So, it is hard to apply unit testing on when business logic depends on it (the method cannot be mocked).

Using the code

It is very simple that using this function, like this:

var basePath = @"D:\Workspace\YourSolution\YourProject";  // The dir contains the .csproj file.
var webReference = "WebReference";                        // The namespace of the web reference you set.
var puller = new InterfacePuller(basePath, webReference);

A code file named "ReferenceExtensions.cs" will be generated under the path <basePath>/Web References/<webReference>.

Now, you can declare the fields with the interface type instead of the client stub class type.

[__strike__]private WebService service = new WebService(); 
private IWebService service = new WebService();  


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


About the Author

China China
No Biography provided

You may also be interested in...


Comments and Discussions

Questionproblem with code snippet Pin
SHkaff++14-Aug-13 21:58
memberSHkaff++14-Aug-13 21:58 

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
Web04 | 2.8.170813.1 | Last Updated 8 Apr 2013
Article Copyright 2013 by 吴骏明
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid