WCF返回JSON格式数据问题

moonface007 2011-11-29 01:14:26
关键代码如下:
public interface IService
{
[OperationContract(Name="sayHelloJson")]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "sayHello", BodyStyle = WebMessageBodyStyle.Wrapped)]
String sayHello();
[OperationContract(Name = "SendMessageJson")]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "SendMessage?Message={Message}", BodyStyle = WebMessageBodyStyle.Wrapped)]
String SendMessage(String Message);
}

static void Main(string[] args)
{
Uri ea = new Uri("http://localhost:8000/Service");
WebHttpBinding bb = new WebHttpBinding();
ServiceHost sh = new ServiceHost(typeof(Service),ea);
ServiceMetadataBehavior behave = new ServiceMetadataBehavior();
behave.HttpGetEnabled = true;
sh.Description.Behaviors.Add(behave);
sh.AddServiceEndpoint(typeof(IService),bb,ea);
try
{
sh.Open();
Console.WriteLine("启动成功……");
Console.ReadLine();
sh.Close();
}
catch
{
Console.WriteLine("启动失败……");
}

}
没使用配置文件
浏览器访问http://localhost:8000/Service正常
现在想在浏览器中查看sayHello方法的返回数据
http://localhost:8000/Service/Json/sayHello无法打开
到底哪里有问题?
...全文
103 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
softtechnology 2012-03-26
  • 打赏
  • 举报
回复
public interface IService需要加上[ServiceContract]进行标记

[ServiceContract]
public interface IService

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧