使课程成为成熟的网络服务

发布于 2024-09-18 08:39:13 字数 120 浏览 2 评论 0原文

我没有使用 Visual Studio 2010。我有一个标记为 webmethod 的类文件。 我可以使用针对 .NET 3.5 框架的 C# 编译器来编译它。

我怎样才能把它变成一个网络服务?有什么想法吗?

I am not using Visual Studio 2010. I have a class file that I marked as a webmethod.
I am able to compile it using C# compiler targetting the .NET 3.5 framework.

How can I make this a webservice? Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

月亮是我掰弯的 2024-09-25 08:39:13

一般来说,这是一个坏主意。

Web 服务通常设计为以面向服务的方式运行。它期望通过网络进行调用,并且在设计时就考虑到了这一点。

类通常被设计为在与其方法的调用者相同的进程中运行。例如,调用类的方法通常成本低廉,因此设计具有许多细粒度方法的类是有意义的。调用 Web 服务通常比较昂贵,因为调用通常会通过网络进行。使用更少的、粗粒度的方法来设计服务更有意义。

Web 服务通常应设计为无状态的。一般来说,一个类可以维护状态。一个例子是代表银行帐户的类。对于这样的类来说,维护帐户余额的运行总计并在调用 Deposit 和 Withdraw 方法时更改该总计是非常有意义的。但是,您不希望为网络上的每笔交易调用存款和取款。相反,您可以向服务发送一个 Transaction 对象列表,每个对象代表一次存款或取款。您可以通过一次操作将列表发送到服务,而不是通过网络多次调用。

In general, this is a bad idea.

A web service is generally designed to operate in a Service-Oriented manner. It expects to be called across a network, and is designed with that in mind.

A class is generally designed to operate in a the same process as the callers of its methods. For instance, calling the methods of a class is usually inexpensive, so it makes sense to design the class with many fine-grained methods. Calling a web service is generally more expensive because the calls will usually go across a network. It makes better sense to design the service with fewer, course-grained methods.

A web service should usually be designed to be stateless. A class, in general, can maintain state. An example would be a class that represents a bank account. It makes perfect sense for such a class to maintain a running total of the account balance, and to change that total when Deposit and Withdraw methods are called. However, you would not want to call Deposit and Withdraw for every transaction across a network. Instead, you might send the service a list of Transaction objects, each representing a Deposit or Withdrawal. You would send the list to the service in a single operation, rather than calling across the network many times.

婴鹅 2024-09-25 08:39:13

First, make sure that your class inherits from WebService. Then add a new WebService ASMX file/class to your project. Have the new class inherit your main class. You;ll then be able to access the new webservice through a the url. ex, http://example.com/WebService.asmx

脸赞 2024-09-25 08:39:13

通常,当您将 WebService 作为 Web 项目使用时,它会自动配置。对于普通的类库,最好使用WCF类,并为该类标记使用OperationContract。

对于 WCF,配置类库也非常容易。

Generally a WebService is configured automatically when you use it as a Web project. For normal class library, it is better to use WCF classes and mark using OperationContract for the class.

Configuring a class library is also very easy in case of WCF.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文