Reputation: 917
I am implementing WCF Rest WebGet service which returns data in json format. It perfectly works on localhost and local IIS.
This is how I call webservice on localhost:
http://localhost:59395/WallpaperService.svc/GetCategory?intId=1
But it does not work on server.
Below two scenarios on server does not work:
(1) http://xyz.co.in/WallpaperService.svc
It gives below error:
"Endpoint not found. Please see the service help page for constructing valid requests to the service."
(2) http://xyz.co.in/WallpaperService.svc/GetCategory?intId=1
It gives below error: HTTP 404 Resource not found
Code Snippet:
1. IWallpaperServices.cs
using System.Text;
namespace AwesomeWallpapers
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IAndroidAppWCF" in both code and config file together.
[ServiceContract]
public interface IWallpaperService
{
[OperationContract]
[WebGet(UriTemplate = "GetCategory?intId={intId}",ResponseFormat=WebMessageFormat.Json)]
string GetCategory(int intId);
}
}
2. WallpaperService.svc
<%@ ServiceHost Language="C#"
Debug="true"
Service="AwesomeWallpapers.WallpaperService"
CodeBehind="WallpaperService.svc.cs"
Factory="System.ServiceModel.Activation.WebServiceHostFactory"%>
3. WallpaperService.svc.cs
using AwesomeWallpapers.Controllers;
using AwesomeWallpapers.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Web.Script.Serialization;
namespace AwesomeWallpapers
{
public class WallpaperService : IWallpaperService
{
public string GetCategory(int intId)
{
try
{
List<Category_GetAllResult> lstCategory = new List<Category_GetAllResult>();
DataController objController = new DataController();
lstCategory = objController.GetAllCategory(intId);
if (lstCategory != null && lstCategory.Count > 0)
{
JavaScriptSerializer js = new JavaScriptSerializer();
return js.Serialize(lstCategory);
}
}
catch (Exception ex)
{
ErrorLog.Write(ex);
}
return string.Empty;
}
}
}
4. Web.config
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=152368
-->
<configuration>
<connectionStrings>
<add name="TestDBConnectionString" connectionString="Data Source=x.y.z.a;Initial Catalog=WallsNRings;User ID=abc;Password=abc"
providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="1.0.0.0"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages"/>
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.serviceModel>
<services>
<service behaviorConfiguration="Default" name="AwesomeWallpapers.WallpaperService">
<endpoint address=""
behaviorConfiguration="webBehavior"
binding="webHttpBinding"
contract="AwesomeWallpapers.IWallpaperService" />
<endpoint contract="IMetadataExchange"
binding="mexHttpBinding"
address="mex" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp helpEnabled="true" automaticFormatSelectionEnabled="true"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Default">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
I tried different tags in Web.config but nothing works.
Please help or suggest any ideas.
Let me know if any additional information is required.
Upvotes: 0
Views: 1124
Reputation: 41
You're pointing the address to mex
<endpoint contract="IMetadataExchange"
binding="mexHttpBinding"
address="mex" />
So try put mex at the of your url, like:
http://xyz.co.in/WallpaperService.svc/mex
Upvotes: 1