wcf经典
来源:互联网 发布:星型网络拓扑结构原理 编辑:程序博客网 时间:2024/06/01 08:30
using System;
using System.ServiceModel;
using System.ServiceModel.Description;
namespace Project1
{
// Define a service contract.
[ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")]
public interface ICalculator
{
[OperationContract]
double Add(double n1, double n2);
[OperationContract]
double Subtract(double n1, double n2);
[OperationContract]
double Multiply(double n1, double n2);
[OperationContract]
double Divide(double n1, double n2);
}
// Service class that implements the service contract.
// Added code to write output to the console window.
public class CalculatorService : ICalculator
{
public double Add(double n1, double n2)
{
double result = n1 + n2;
Console.WriteLine("Received Add({0},{1})", n1, n2);
Console.WriteLine("Return: {0}", result);
return result;
}
public double Subtract(double n1, double n2)
{
double result = n1 - n2;
Console.WriteLine("Received Subtract({0},{1})", n1, n2);
Console.WriteLine("Return: {0}", result);
return result;
}
public double Multiply(double n1, double n2)
{
double result = n1 * n2;
Console.WriteLine("Received Multiply({0},{1})", n1, n2);
Console.WriteLine("Return: {0}", result);
return result;
}
public double Divide(double n1, double n2)
{
double result = n1 / n2;
Console.WriteLine("Received Divide({0},{1})", n1, n2);
Console.WriteLine("Return: {0}", result);
return result;
}
}
class WCFServer
{
static void Main(string[] args)
{
// Step 1 of the address configuration procedure:
// Create a URI to serve as the base address.
Uri baseAddress = new Uri("http://localhost:8000/ServiceModelSamples/Service");
// Step 2 of the hosting procedure: Create ServiceHost
ServiceHost selfHost = new ServiceHost(typeof(CalculatorService), baseAddress);
try
{
// Step 3 of the hosting procedure: Add a service endpoint.
selfHost.AddServiceEndpoint(
typeof(ICalculator),
new WSHttpBinding(),
"CalculatorService");
// Step 4 of the hosting procedure: Enable metadata exchange.
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
selfHost.Description.Behaviors.Add(smb);
// Step 5 of the hosting procedure: Start (and then stop) the service.
selfHost.Open();
Console.WriteLine("The service is ready.");
Console.WriteLine("Press <ENTER> to terminate service.");
Console.WriteLine();
Console.ReadLine();
// Close the ServiceHostBase to shutdown the service.
selfHost.Close();
}
catch (CommunicationException ce)
{
Console.WriteLine("An exception occurred: {0}", ce.Message);
selfHost.Abort();
}
}
}
}
- wcf经典
- 一个经典的WCF解析
- WCF 开发示例向导 -- 经典推荐!
- WCF 开发示例向导 Part 1 --- 经典推荐!
- WCF 开发示例向导 Part 2 --- 经典推荐!
- WCF 开发示例向导 Part 3 --- 经典推荐
- 经典技术书籍分享(5):《WCF技术内幕》封面预览
- 《C#入门经典v6》读书笔记5 WCF&WWF
- Wcf
- WCF
- WCF
- WCF
- Wcf
- Wcf
- WCF
- wcf
- Wcf
- WCF
- C#.Net ArrayList的使用
- Android全屏对话框(附带延时关闭效果)
- [调试相关]android的log解析
- struts运行原理
- JavaScript execCommand用法举例
- wcf经典
- C#中的委托和事件(转载学习)
- android文件操作
- (二)插入排序:直接插入排序,希尔排序
- 优酷clear
- valgrind详细说明
- 工作只需20年
- poj1976
- WebKit加载网页的流程(dlmu2001)