尝试创建一个简单的服务,通过以下几个教程返回一个简单的JSON字符串.我被两个不同的机器卡在了一个HTTP Statuscode 400错误请求上.示例教程使用JSON pt.1和pt.2的RESTful WCF服务 - http://www.youtube.com/watch?v=5BbDxB_5CZ8
我也有谷歌并在这里搜索(StackOverflow)类似的问题没有成功.
问题是我在尝试进行健全性检查以浏览到WCF服务并执行该方法时收到400错误请求.通过编译服务并浏览此地址:http:// localhost:49510/Service1.svc/GetPerson 就像教程一样.我试过找3天的解决方案.任何帮助表示赞赏.
这就是我的工作.
首先,我创建一个简单的WCF服务应用程序的新项目.我删除了默认的Service1.svc并添加了一个新的WCF服务,它生成了一个新的Service1.svc和一个IService1.cs
这是接口的代码(IService1.cs)
namespace WcfService1
{
// 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]
[WebInvoke(Method="GET", BodyStyle=WebMessageBodyStyle.Bare, ResponseFormat=WebMessageFormat.Json, RequestFormat=WebMessageFormat.Json, UriTemplate="GetPerson")]
Person GetPerson();
}
[DataContract(Name="Person")]
public class Person
{
[DataMember(Name="name")]
public string Name { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
这是Service1.svc的代码
namespace WcfService1
{ …Run Code Online (Sandbox Code Playgroud)