using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;namespace MagicEightBallServiceLib
{
[ServiceContract]
public interface IEightBall
{
[OperationContract]
string ObtainAnswer(string userQuestion);
}
public class MagicEightBallService:IEightBall
{
#region IEightBall 成员
public MagicEightBallService()
{
Console.WriteLine("The magic 8 ball awaits for your answer");
}
public string ObtainAnswer(string userQuestion)
{
string[] answer = { "Future uncertain", "yes", "no", "Hazy" };
Random r = new Random();
return String.Format("{0}?{1}", userQuestion, answer[r.Next(answer.Length)]);
} #endregion
}
}<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="MagicEightBallServiceLib.MagicEightBallService">
<endpoint address="http://localhost:8080/MagicEightBallService"
binding="basicHttpBinding" contract="MagicEightBallServiceLib.IEightBall"/>
</service>
</services>
</system.serviceModel>
</configuration>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using MagicEightBallServiceLib;namespace MagicEightBallServiceHost
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Console basic WCF host");
using (ServiceHost serviceHost=new ServiceHost("MagicEightBallService"))
{
serviceHost.Open();
Console.WriteLine("The service is ready");
Console.WriteLine("Press the enter key to terminate");
Console.ReadLine();
}
}
}
}
解决方案 »
- 取文件物理地址.高分
- css 自动补充图片空白的位置
- Url重新出问题
- Logo设计求助
- 做asp.net程序员,要掌握哪些知识?现在vs2003和vs2005哪种用的多一些?找asp.net的工作好难
- C# ASP.NET DataGrid编辑时怎么控制不可修改的字段不出现Textbox控件?
- 用户验证中大家都用什么样的方式啊?
- dataReader怎么记录指针移到行尾,并取取得记录
- 怎样截取DataGrid中的字符串
- window.confirm的问题!
- 关于虚拟机开发ASP.NET的问题
- 关于 asp.net 的iis “ 若要访问本地IIS网站,必须在管理员的上下文运行Visual Studio ?”
你初始化的用的是MagicEightBallService
自己先看看手册
http://msdn.microsoft.com/zh-cn/library/system.servicemodel.servicehost.aspx
打开host那部分不对
using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService)))
可以依然报这个服务有零个应用程序(非基础结构)终结点,求帮忙啊