При попытке создать простой сервис для возврата простой строки JSON, следуя нескольким учебникам. Я застрял на двух разных машинах с неправильным запросом HTTP Statuscode 400.
Пример учебников
Служба RESTful WCF с JSON pt.1 & pt.2 - http://www.youtube.com/watch?v=5BbDxB_5CZ8
Я также Google и искал здесь (StackOverflow) для аналогичной проблемы без успеха.
Проблема в том, что я получаю неверный запрос 400 при попытке выполнить проверку работоспособности, чтобы перейти к службе WCF и выполнить метод. Составив сервис и просмотрите этот адрес: 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; }
}
}
Вот код для Service1.svc
namespace WcfService1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class Service1 : IService1
{
public Person GetPerson()
{
return new Person() { Name = "Tobbe" };
}
}
}
И Web.config не тронут и выглядит вот так web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>