WCF - Creating WCF Service
http://www.tutorialspoint.com/wcf/wcf_creating_service.htm
Creating a WCF service is a simple task using Microsoft Visual Studio 2012. Given below is the step-by-step method for creating a WCF service along with all the requisite coding, to understand the concept in a better way.
在VS2012中创建一个wcf服务是一个简单的任务。为了更好的理解之前的概念,按照下面的方法,一步一步的创建一个wcf服务,同时也包含了所有必须的编码
- Launch Visual Studio 2012. 首先启动vs2012
- Click on new project, then in Visual C# tab, select WCF option. 新建项目,然后选择模板-->C#-->WCF 右侧选择wcf库
A WCF service is created that performs basic arithmetic operations like addition, subtraction, multiplication, and division. The main code is in two different files – one interface and one class.
A WCF contains one or more interfaces and its implemented classes.
我们创建一个执行基础算数运算的wcf服务:实现加减乘除。主要的代码在2个不同的文件中,一个接口另外是类
wcf包含至少一个接口以及实现了接口的类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text; namespace WcfServiceLibrary1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to
// change the interface name "IService1" in both code and config file
// together.
[ServiceContract]
public interface IService1
{
[OperationContract]
int Sum(int numer1, int number2); [OperationContract]
int Substract(int number1, int number2); [OperationContract]
int Multiply(int number1, int number2); [OperationContract]
int Divide(int number1, int number2);
} // Use a data contract as illustrated in the sample below to add
// composite types to service operations.
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello "; [DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
} [DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
}
The code behind its class is given below. 实现了接口的类如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text; namespace WcfServiceLibrary1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to
// change the class name "Service1" in both code and config file
// together.
public class Service1 : IService1
{
/// <summary>
/// This Function Returns summation of two integer numbers
/// </summary>
/// <param name="number1"></param>
/// <param name="number2"></param>
/// <returns></returns>
public int Sum(int number1, int number2)
{
return number1 + number2;
} /// <summary>
/// This function returns subtraction of two numbers.
/// If number1 is smaller than number2 then this function returns 0
/// </summary>
/// <param name="number1"></param>
/// <param name="number2"></param>
/// <returns></returns>
public int Substract(int number1, int number2)
{
if (number1 > number2)
{
return number1 - number2;
}
else
{
return ;
}
} /// <summary>
/// This function returns multiplication of two integer numbers.
/// </summary>
/// <param name="number1"></param>
/// <param name="number2"></param>
/// <returns></returns>
public int Multiply(int number1, int number2)
{
return number1 * number2;
} /// <summary>
/// This function returns integer value of two integer number.
/// If num2 is 0 then this function returns 1
/// </summary>
/// <param name="number1"></param>
/// <param name="number2"></param>
/// <returns></returns>
public int Divide(int number1,int number2)
{
if (number2 != )
{
return number1 / number2;
}
else
{
return ;
}
}
}
}
To run this service, click the Start button in Visual Studio.
While we run this service, the following screen appears.
服务运行起来之后,会出现以下的界面。 双击某一个函数来执行相应的操作
On clicking the sum method, the following page opens. Here, you can enter any two integer numbers and click on the Invoke button. The service will return the summation of those two numbers.
双击了Sum方法后,会出现下面的页面。可以输入number和number2的值,然后点击调用。然后服务会返回2个数字的和。
Like summation, we can perform all other arithmetic operations which are listed in the menu. And here are the snaps for them.
The following page appears on clicking the Subtract method. Enter the integer numbers, click the Invoke button, and get the output as shown here:
The following page appears on clicking the Multiply method. Enter the integer numbers, click the Invoke button, and get the output as shown here:
The following page appears on clicking the Divide method. Enter the integer numbers, click the Invoke button, and get the output as shown here:
Once the service is called, you can switch between them directly from here.
一旦某一个方法的服务被调用后,可以直接通过tab和切换它们,也可以重新打开一个新的
WCF - Creating WCF Service的更多相关文章
- wcf和web service的区别
1.WebService:严格来说是行业标准,不是技术,使用XML扩展标记语言来表示数据(这个是夸语言和平台的关键).微软的Web服务实现称为ASP.NET Web Service.它使用Soap简单 ...
- WCF和Web Service的 区(guan)别(xi)
参考文献:http://social.microsoft.com/Forums/zh-CN/c06420d1-69ba-4aa6-abe5-242e3213b68f/wcf-webservice 之前 ...
- WCF与 Web Service的区别是什么?各自的优点在哪里呢?
这是很多.NET开发人员容易搞错的问题.面试的时候也经常遇到,初学者也很难分快速弄明白 Web service: .net技术中其实就指ASP.NET Web Service,用的时间比较长,微软其实 ...
- 跟我一起学WCF(13)——WCF系列总结
引言 WCF是微软为了实现SOA的框架,它是对微乳之前多种分布式技术的继承和扩展,这些技术包括Enterprise Service..NET Remoting.XML Web Service.MSMQ ...
- Learing WCF Chapter1 WCF Services
WCF ServicesWCF services are the new distributed boundary in an enterprise application—with an empha ...
- WCF - Consuming WCF Service
WCF services allow other applications to access or consume them. A WCF service can be consumed by ma ...
- WCF - Hosting WCF Service
After creating a WCF service, the next step is to host it so that the client applications can consum ...
- WCF - Hosting WCF Service 四种托管方式
https://www.tutorialspoint.com/wcf/wcf_hosting_service.htm After creating a WCF service, the next st ...
- 使用WCF 创建 Rest service
REST SERVICE 允许客户端修改url路径,并且web端功过url 请求数据. 他使用http协议进行通讯,想必大家都知道 . 并且我们可以通过设置进行数据类型转换, 支持XML,JSON 格 ...
随机推荐
- 第一篇、CSS3_transtion的使用
<html> <head> <title>这是一个CSS3的特性</title> <style> #box{ width: 150px; h ...
- GCD 多线程
Grand Central Dispatch (GCD)是Apple开发的一个多核编程的较新的解决方法.它主要用于优化应用程序以支持多核处理器以及其他对称多处理系统.它是一个在线程池模式的基础上执行的 ...
- 适配----Autolayout
AutLayout 相对布局,根据参照视图的位置 来定义自己的位置.通过约束视图和视图之间的关系来分配屏幕上的位置,通常与VFL语言配合使用 VFL(visual format language)视觉 ...
- 【html】【8】div布局[子div在父div居底]
从今天起 开始细话div布局 思路及要点: 父div的位置设置成相对的,即“position: relative;”. 而子div的位置设置成绝对的,并且下边缘设为0,即“position: ab ...
- Java实战之04JavaWeb-01Servlet
一.Http协议 1.什么是http协议? http协议就是描述客户端与服务器端交互过程的 2.http的请求 3.http的响应 二.Servlet的简介 1.Servlet的概述 Servlet: ...
- n个骰子的点数
把n个骰子扔在地上,所有骰子朝上的一面的点数之和为s.输入n,打印出s的所有可能的值和出现的概率. 解法一:基于递归求骰子点数. /////////////////基于递归求骰子点数///////// ...
- 清橙 A1120 拦截导弹 -- 动态规划(最长上升子序列)
题目地址:http://oj.tsinsen.com/A1120 问题描述 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但 ...
- 一套帮助你理解C语言的测试题(转)
前言 原文链接:http://www.nowamagic.net/librarys/veda/detail/775 内容 在这个网站(http://stevenkobes.com/ctest.html ...
- Blu-Ray BRRip 和 BDRip 的区别
Blu-Ray BRRip & BDRip 的区别 最近看电影有点多,常常看到blueray或者BDRip的格式,所以找了一下这两种格式的区别. BRRip = 来自蓝光盘片的xvid编码 B ...
- WCF SOA服务应用
WCF是微软官方推出的一个基于服务的整合框架,它整合了以前的Web Service.MSMQ.Remoting等通信技术,通过灵活的配置,让服务编程更加容易.可扩展.这篇文章主要目的就是带领大家从开发 ...