December 19, 2020

WCF Proxy generation – using SvcUtil.exe

SvcUtil.exe is the the ServiceModel Metadata Utility tool used to generate service model code from the service URL or wsdl file.

In this example, we will generate client proxy classes by using service URL.

First make sure to have the target service up and running.

After verifying the service status go to Visual Studio Command Prompt and run the following command.

svcutil https://localhost:8081/OrderManagement/OrderManagement.svc /Language=c# 
		/t:Code /out:OrderManagementProxy.cs 
                /config:OrderManagementProxy.config

It contains following parameters:

  • First is the URL of the target service.
  • /Language specifies the output language in which we want to generate code.
  • /t Specifies the output to be generated by the tool, since we are generating proxy code so we will provide the value code.
  • /out Specifies the target file name for the generated code.
  • /config Specifies the filename for the generated configuration file, Default value is output.config

For config file you can also use another parameter /mergeConfig. It merges the generated configuration into an existing file, instead of overwriting the existing file. This will be useful if you provide your regular application's config file in the /config paramter, so in that case you dont want to overwrite that config file but to merge the new changes with existing configuration. For example like this:

svcutil https://localhost:8081/OrderManagement/OrderManagement.svc /Language=c# 
		/t:Code /out:OrderManagementProxy.cs 
                /config:app.config /mergeConfig

You can find the generated output code in the file OrderManagementProxy.cs in the current directory from where you run this command.

References:

Related Post(s):

No comments:

Post a Comment