如何使用 WSDL 文件创建 WCF 服务(不是打电话) [英] How to use a WSDL file to create a WCF service (not make a call)

查看:23
本文介绍了如何使用 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.

这篇关于如何使用 WSDL 文件创建 WCF 服务(不是打电话)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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