启动合同优先 WCF 或 Web 服务的最佳方式? [英] Best way to start Contract First WCF or Web Service?

查看:27
本文介绍了启动合同优先 WCF 或 Web 服务的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了一个 WSDL 文件和几个 XSD 文件来为其构建 Web 服务.现在我正在尝试将其设置为接收请求和响应.

I've been given a WSDL file and several XSD files to build a web service for. Right now I'm trying to just get it setup to receive requests and respond.

我在 WebServices 方面的经验仅限于带有 asmx 文件等的旧 asp 版本.

My experience with WebServices is limited to the old asp version with an asmx file etc.

XSD 文件中有很多信息,我不想手动构建这些类,我也不太明白这到底会带来什么(我想只是一个 xml 可序列化类,但没有没仔细看).

There is a lot of information in the XSD files, I don't want to build out the classes by hand, nor do I really understand exactly what that would entail anyways (I'd imagine just an xml serializable class but haven't looked into it).

我从哪里开始呢?我研究了 WCF,但它对我来说完全陌生,所以我宁愿使用旧样式,但我正在努力寻找有关如何设置它的任何信息或从 XSD 文件自动生成类的先机.

Where do I start with this? I looked into WCF but its completely foreign to me so I'd kinda rather use the old style, but I'm struggling to find any info on how to set that up or get a head start with automated generation of classes from the XSD files.

我确实尝试过 WCF,但是当我尝试生成 WebService 代码时,WSCF blue 给了我错误(Cannot import wsdl:portType).并且 svcutil.exe 将生成 一些 XSD 文件信息,但由于某种原因不是全部.

I did try WCF a bit, but WSCF blue gives me errors (Cannot import wsdl:portType) when I try to generate the WebService code. And svcutil.exe will generate some of the XSD file info but not all of them for some reason.

所以两个问题:

  1. 如何从 XSD 文件生成一些存根类以实现这一目标

  1. How can I generate some stub classes from XSD files to get this going

从一个 WSDL 和多个 使用 wscf blue 的 XSD 文件生成 WCF 服务的教程/演练?

A tutorial/walkthrough for generating a WCF service from a WSDL and multiple XSD files that does not use wscf blue?

推荐答案

假设您有一个 WSDL,您可以执行以下操作.当我的任务是在现有 Web 服务之上实现一个中间调度层时,我就这样做了.新服务应该公开与原始服务相同的接口,但在内部执行不同的功能.请注意,我在这里谈论的是经典"WCF 服务(基于 SOAP).

Assuming you have a WSDL to start with, you can do the following. I did this when tasked with implementing an intermediate dispatch layer on top of an existing web service. The new service should expose the same interface as the original service but perform different functions internally. Note that I am talking about "classical" WCF services here (SOAP-based).

第 1 步:从 WSDL 为服务接口创建代码

Step 1: Create code for the service interface from the WSDL

wsdl.exe /si /out:<targetfolder> <url-to-wsdl>

这会生成一个 .cs 文件,其中包含接口和附加数据类型(用于传输对象).请注意,此文件还不是 WCF 就绪的,因为 wsdl.exe 似乎假设您要创建旧的 .asmx 服务.

This generates a .cs file that contains the interfaces and additional data types (for transfer objects). Note that this file is not WCF-ready yet as wsdl.exe seems to assume you want to create an old .asmx service.

第 2 步:将界面代码导入您的项目

Step 2: Import interface code into your project

将生成的文件添加到您的项目中.添加用于使接口及其操作 WCF 就绪的属性.您需要在接口中添加[ServiceContract],在操作中添加[OperationContract].

Add the generated file to your project. Add attributes for making the interfaces and their operations WCF-ready. You need to add [ServiceContract] to the interfaces and [OperationContract] to the operations.

第 3 步:创建 WCF 服务

创建 WCF 服务(.svc 文件)并去掉生成的接口.相反,让服务从生成的接口实现契约.现在,您可以实现新功能了.

Create a WCF service (.svc file) and get rid of the generated interface. Instead, make the service implement the contract(s) from the generated interfaces. Now, you can implement the new functionality.

第 4 步:调整剩余绑定、身份验证设置等以匹配原始 Web 服务.

Step 4: Adjust the remaining binding, authentication settings etc. to match the original web service.

这篇关于启动合同优先 WCF 或 Web 服务的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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