I am using wcf service where i have to access wcf service method and show the returned json data in the browser itself. Currently i tried string method so json data is showing as json string format which is incorrect. I have gone through this link and tried with my code but not getting any data because of complete data is in one list.
Below is the interface IService code:
[ServiceContract]
public interface IService1
{
[OperationContract]
List<SuccessStoryApp> GetSuccessStoryJson();
[OperationContract]
[WebInvoke(Method = "GET",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/GetBlogList/")]
string GetBlogList();
}
Service1.svc Code:
public string GetBlogList()
{
log.Info("GetBlostList method entered");
List<SuccessStoryApp> storyList = new List<SuccessStoryApp>();
string jsonString = string.Empty;
var jsonData = GetSuccessStoryJson();
storyList = jsonData.Select(x => new SuccessStoryApp
{
Author = x.Author,
AuthorSlug = x.AuthorSlug,
Available = x.Available,
Category = x.Category,
CountryCode = x.CountryCode,
Description = x.Description,
LanguageCode = x.LanguageCode,
PublishedDate = x.PublishedDate,
Quote = x.Quote,
ShortDescription = x.ShortDescription,
StoryImageAlt = x.StoryImageAlt,
StoryImageTitle = x.StoryImageTitle,
StoryImageURL = x.StoryImageURL,
Tags = x.Tags,
Text = x.Tags,
Title = x.Title,
TitleImageURL = x.TitleImageURL,
Type = x.Type
}).ToList();
if (storyList.Count > 0)
{
var json = JsonConvert.SerializeObject(storyList);
jsonString = json;
}
else
{
jsonString = "Some error occurred";
}
return jsonString;
}
<system.serviceModel>
<services>
<service behaviorConfiguration="Default" name="BlogService.Service1">
<endpoint address="" behaviorConfiguration="webBehavior" binding="webHttpBinding" contract="BlogService.IService1" bindingConfiguration="WHB" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:60500/Service1.svc" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp defaultOutgoingResponseFormat="Json" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
<behavior name="Default">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="WHB" crossDomainScriptAccessEnabled="true">
<security mode="None" />
</binding>
</webHttpBinding>
</bindings>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>