简体   繁体   English

合同第一SOA和WCF合同

[英]Contract First SOA and WCF Contracts

I have a simple question. 我有一个简单的问题。 I am using WCF to create web services. 我正在使用WCF创建Web服务。 I have created all the services without filling the operation bodies. 我创建的所有服务都没有填充操作体。 Now I have the wsdl files auto-generated from the service contracts. 现在,我有了根据服务合同自动生成的wsdl文件。 Is this approach "Contract First", if I am coding the operation implementations later? 如果稍后要对操作实现进行编码,则此方法是否为“合同第一”?

Yes, because you're defining the contract between you and anyone consuming your API first. 是的,因为您正在定义自己与任何先使用API​​的人之间的合同。 Usually (but not always) the contract/API is defined via an interface. 通常(但不总是)合同/ API是通过接口定义的。

Edit: As Namphibian said in the comments, if you're building web services contract first, then you would want to define your WSDL first and generate the code from there. 编辑:正如Namphibian在评论中所说,如果您首先要构建Web服务合同,那么您首先要定义WSDL并从那里生成代码。 My answer assumed you wanted to develop a .NET API contract first and that you were going to expose it as a web service after the fact. 我的回答假设您想先开发.NET API合同,然后再将其作为Web服务公开。

Second edit: I wanted to add that SOA principles themselves have nothing to do with web services. 第二次编辑:我想补充一下SOA原则本身与Web服务无关。 You can build services that are only exposed via their codified API. 您可以构建仅通过其编码API公开的服务。

This is not quite correct. 这不是很正确。 You are simulating contract first but you are still relying on the .Net framework to generate the WSDL. 您首先要模拟合同,但仍要依靠.Net框架来生成WSDL。 In contract first/WSDL first coding(top down) approach you author a WSDL file with a tool such as XML Spy etc. Then you generate the code from the WSDL. 在合同优先/ WSDL首先编码(自上而下)方法中,您使用XML Spy等工具编写WSDL文件。然后从WSDL生成代码。 In your approach you are creating a WSDL from interfaces. 在您的方法中,您正在从接口创建WSDL。

Using interfaces is the most successful way of doing this type of development however you are still doing the code first. 使用接口是进行这种类型开发的最成功方法,但是您仍然要先进行代码。 Let me clarify that with an example. 让我用一个例子来阐明这一点。 Typically in a SOA architecture developers follow the WSDL first approach. 通常,在SOA架构中,开发人员遵循WSDL优先方法。 In the WSDL first approach you would typically submit your WSDL file for review by a SOA governance body in your company. 在WSDL优先方法中,通常将提交WSDL文件,以供公司中的SOA治理机构审查。 This WSDL will then be measured against SOA governance policies to see if it fits. 然后将根据SOA治理策略对该WSDL进行评估,以了解其是否合适。 Once approved only then would code artifacts get generated. 一旦获得批准,则将生成代码工件。

What you are doing is not wrong but it is NOT contract first approach. 您在做什么并没有错,但这不是契约优先的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM