0
url에서 wcf rest service를 호출하려고하지만이 오류와 같은 오류가 표시됩니다 : 가장 많은 원인 : • 입력 오류가있을 수 있습니다. 주소. • 링크를 클릭하면 내용이 오래되었을 수 있습니다.wcf rest service 400 오류 : 주소에 입력 오류가있을 수 있습니다.
Iservice.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace SampleRestSample
{
interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "Book/{id}", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
List<Prasad> GetBookById(string id);
}
[DataContract]
public class Prasad
{
[DataMember]
public string Name { get; set; }
[DataMember]
public string Age { get; set; }
}
}
Service1.svc.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace LoginRestSample
{
// 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 : SampleRestSample
{
List<Prasad> list = new List<Prasad>();
public List<Prasad> GetBookById(string id)
{
try
{
Prasad cls = new Prasad();
cls.Age = "24";
cls.Name = "prasad";
list.Add(cls);
//int bookId = Convert.ToInt32(id);
//using (SampleDbEntities entities = new SampleDbEntities())
//{
// return entities.Books.SingleOrDefault(book => book.ID == bookId);
//}
}
catch
{
throw new FaultException("Something went wrong");
}
return list;
}
}
}
의 Web.config
:내가 모바일 앱 여기
내 코드
에 대한 JSON의 responce 필요<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
</system.web>
<system.serviceModel>
<services>
<service name="WcfRestSample.SampleRestSample">
<endpoint address="" behaviorConfiguration="restfulBehavior"
binding="webHttpBinding" bindingConfiguration="" contract="WcfRestSample.ISampleRestSample" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/SampleRestSample" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="restfulBehavior">
<webHttp automaticFormatSelectionEnabled="true" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
모든 솔루션
미리 감사드립니다.