如何使用SvcUtil.exe生成WCF服务 [英] How to generate WCF service with SvcUtil.exe

查看:132
本文介绍了如何使用SvcUtil.exe生成WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 SvcUtil.exe 从wsdl文件生成 IClassName.cs 文件,并且工作正常。我的问题是我不知道如何使用SvcUtil.exe的命令参数生成 ClassName.svc 文件。

I am using SvcUtil.exe to generate IClassName.cs file from wsdl file and that is working fine. My problem is that I do not know how to generate ClassName.svc file using command arguments for SvcUtil.exe.

运行SvcUtil之后。 exe我想获得WCF服务,就像从包含所有类* .svc,*。cs和接口的Visual Studio向导中创建时一样。

After running the SvcUtil.exe I would like to get WCF service like when you created from Visual Studio Wizard containing all classes *.svc, *.cs, and interface.

谢谢您,
Skrch

Thank You, Skrch

推荐答案

首先要生成代理类,我们需要启动并运行我们的服务。因此,在使用此实用程序之前,请确保您的服务正在运行,没有任何问题。

First of all to generate proxy class we need to have our service up and running. So before using this utility make sure that your service is running without any issue.

在验证服务状态之后,请转到Visual Studio命令提示符并运行以下命令。

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

svcutil http://localhost/MyService/ClassName.svc /Language=c#
/t:Code /out:ClassNameProxy.cs /config:ClassNameProxy.config

在上述命令中,您应该替换服务URL( http://localhost/MyService/Service1.svc )以及您的服务的网址。
因为我的服务是在c#.net中开发的,所以我选择使用/ Language = c#标志以相同的语言生成代理。

In above command you should replace the service URL ( http://localhost/MyService/Service1.svc) with the URL of your service. Since my services is developed in c#.net so I choose to generate the proxies in the same language by using /Language=c# flag.

/ t:代码将指定输出应作为代码生成。

/t:code will specify that the out put should be generated as code.

/out:ClassNameProxy.cs /config:ClassNameProxy.config参数将告诉实用程序按照这些参数值中的指定命名文件。
运行命令后,工具将生成输出文件和配置文件。

/out:ClassNameProxy.cs /config:ClassNameProxy.config parameters will tell the utility to name the files as specified in these parameter values. After you run the command, tool will generate the output file and config file.

之后,只需将ClassNameProxy.cs文件包含到您的项目中并打开ClassNameProxy.config文件,然后将条目复制到您的web.config文件中。
您可能还需要根据项目中使用的名称更新ClassNameProxy.vb文件并更新命名空间。之后,您可以轻松地在代码中引用该服务并调用操作。

After that just include the ClassNameProxy.cs file into your project and open the ClassNameProxy.config file and copy the entries to your web.config file. You may also need to update the ClassNameProxy.vb file and update the namespace as per the one that you are using in your project. After that you can easily reference the service in your code and call the operations.

这篇关于如何使用SvcUtil.exe生成WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆