码迷,mamicode.com
首页 > 其他好文 > 详细

IIS作为WCF宿主,例子

时间:2014-12-01 00:49:58      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:io   os   sp   文件   on   数据   bs   cti   as   

1、新建wcf服务,可以新建类,按照wcf服务的标准进行编写。

  接口:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace MyService
{
[ServiceContract]
public interface IMyService
{

[OperationContract]
void DoWork();

void CloseComputer(string ip);
[OperationContract]
string RegistMyPCInfo(string myPCInfo);
}
}

 实现:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MyService
{
public class Service : IMyService
{

public void DoWork()
{
throw new NotImplementedException();
}

 

public void CloseComputer(string mac)
{

}
public String RegistMyPCInfo(string myPCInfo)
{
return "IP为:" + myPCInfo + "在数据库中注册成功";
}

}
}

2. 只是编写wcf,没有编写配置文件。下面进行宿主的编写。新建空的web程序MyHosting,在工程中新建一个Myservice.svc文件,用记事本编辑添加<%@ ServiceHost Language="C#" Debug="true" Service="MyService.Service"  %> 然后保存。在空web程序中添加引用-》项目-》刚才写的service类项目。进行编译。

3.将MyHosting项目生成,放置IIS服务器下启动。

IIS作为WCF宿主,例子

标签:io   os   sp   文件   on   数据   bs   cti   as   

原文地址:http://www.cnblogs.com/lxdonge/p/4134053.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!