如何使用 WSDL 文件创建 WCF 服务(不是打电话)

如何使用 WSDL 文件创建 WCF 服务(不是打电话)

问题描述:

我有一个旧的 WSDL 文件,我想基于这个 WSDL 文件创建一个服务器.

I have an old WSDL file and I want to create a server based on this WSDL file.

WSDL 是从 ASMX 生成的(我想,但我不确定).

The WSDL is generated from a ASMX (I suppose but I am not sure).

我怎样才能做到这一点?

How can I achieve this ?

原始问题在哪里OP 认为他需要基于 WSDL 创建一个客户端.

original question where the OP thought he needed to create a client based on the WSDL.

使用 svcutil,您可以从 WSDL 创建接口和类(数据协定).

Using svcutil, you can create interfaces and classes (data contracts) from the WSDL.

svcutil your.wsdl (or svcutil your.wsdl /l:vb if you want Visual Basic)

这将在 C# 中创建一个名为your.cs"(或在 VB.NET 中为your.vb")的文件,其中包含所有必要的项目.

This will create a file called "your.cs" in C# (or "your.vb" in VB.NET) which contains all the necessary items.

现在,您需要创建一个MyService"类,它将实现服务接口 (IServiceInterface) - 或多个服务接口 - 这就是您的服务器实例.

Now, you need to create a class "MyService" which will implement the service interface (IServiceInterface) - or the several service interfaces - and this is your server instance.

现在一个类本身并没有真正的帮助 - 您需要在某处托管服务.您需要创建自己的 ServiceHost 实例来托管服务、配置端点等 - 或者您可以在 IIS 内托管您的服务.

Now a class by itself doesn't really help yet - you'll need to host the service somewhere. You need to either create your own ServiceHost instance which hosts the service, configure endpoints and so forth - or you can host your service inside IIS.