How to create a WCF application without using the svcutil.exe tool?
What version of Visual Studio are you using?
VS2008 incorporates the functionality of the svcutil tool. To generate the proxy, click on the Solution Explorer and select 'Add Service Reference', you can then enter the URL of the server, give the namespace a name and off you go.
You may want to expand your question to provide some more details of what you are wanting to achieve.
The svcutil.exe tool (and the equivalent functionality in VS2008) are normally used like this: -
You point it at a service description (a WSDL document) and it generates client-side code and config to help you make a client that can communicate with the services described in the WSDL. The tools can do other things as well, but this is what they're most often used for. I assume it's this use of svcutil.exe that you're referring to.
So if you have an existing service, maybe written using some other stack (not WCF), using svcutil makes your life easier than it would otherwise be. But remember, the code and config generated could have been written by you. Normally the config looks verbose because the tool puts all the defaults in there. If you wrote the config yourself you could probably omit most of it.
If you are writing client and service yourself, using WCF, there is almost no reason why you'd use svcutil.exe. When you define your [ServiceContract] you can use that same definition in both client and service. When you create your service config file it's a simple job to create a client config file based on it - most of the content is the same.
In the end, there's no substitute for understanding what all the code/config generated by svcutil.exe actually means. Then you'll be in a position to work without it.
One way to build your WCF client without using svcutil.exe is to use ChannelFactory. What you would need to do is build the WCF service interface in a separate assembly from the service implementation. You can then reference that interface assembly from both your client and your service.
Once you have the reference, you could use the following code to create a WCF client:
var factory = new ChannelFactory<IMyWcfService>();
var wcfClient = factory.CreateChannel();
bool closedSuccessfully = false;
try
{
// Now you can make calls on the wcfClient object
((ICommunicationObject)wcfClient).Close();
closedSuccessfully = true;
}
finally
{
if (!closedSuccessfully)
{
((ICommunicationObject)wcfClient).Abort();
}
}
Note the cleanup routine. You can't use a using statement reliably to clean up the wcfClient variable. If you do, and the object is in a faulted state, you'll get an exception thrown when the using() block goes out of scope and Dispose() is executed on the wcfClient variable. See Jesse Ezell's blog