The remote server returned an error: (404) Not Found

Sep 20 2014 3:36 PM

I am new to WCF world. I am facing below issue please help me out.

Error Message:

There was no endpoint listening at http://localhost:63024/PresidentsService.svc/GetAllPresidentsXml that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

Inner Exception: “The remote server returned an error: (404) Not Found"


My WCF Service Code is

namespace PresidentsService { [ServiceContract] public interface IPresidentsService { [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "/presidents")] List<President> GetAllPresidentsXml(); } [DataContract] public class President { [DataMember] public int Id { get; set; } [DataMember] public string LastName { get; set; } [DataMember] public string FirstName { get; set; } [DataMember] public string EmailAddress { get; set; } } }

Service Implementation:

namespace PresidentsService
{
public class PresidentsService : IPresidentsService
{
private List<President> _presidents;

internal List<President> Presidents
{
get
{
// If there aren't any presidents in our list, populate with samples and return
_presidents = _presidents ?? new List<President>(SampleData.SamplePresidents);
return _presidents;
}
}
public List<President> GetAllPresidentsXml()
{
return presidents;
}
#endregion // IPresidentsService Methods
}
}

Service Web.Config:

<?xml version="1.0"?>
<configuration>
<appSettings/>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime/>
</system.web>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="restfulBehavior">
<webHttp/>
</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="PresidentsService.PresidentsServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="PresidentsService.PresidentsServiceBehavior" name="PresidentsService.PresidentsService">
<endpoint address="http://localhost:63024/PresidentsService.svc" binding="webHttpBinding" contract="PresidentsService.IPresidentsService" behaviorConfiguration="restfulBehavior">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>

Client Web.Config:

<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime/>
</system.web>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="restfulBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="http://localhost:63024/PresidentsService.svc" binding="webHttpBinding" bindingConfiguration="" contract="PresidentsService.IPresidentsService" name="IPresidentsService" kind="" endpointConfiguration="" behaviorConfiguration="restfulBehavior">
<identity>
<dns value="localhost"/>
<certificateReference storeName="My" storeLocation="LocalMachine" x509FindType="FindBySubjectDistinguishedName"/>
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>

And I am calling the service by a ASP.NET page by below way:

protected void Button1_Click(object sender, EventArgs e)
{
try
{
PresidentsServiceClient client = new PresidentsServiceClient();
var result = client.GetAllPresidentsXml();
}
catch (System.ServiceModel.EndpointNotFoundException ex)
{
}
catch (Exception ex)
{

}
}

So, I am not able to access the service and getting above mentioned error message.

but I can confirm that the service is working well in SOAP UI. Also if I consume this service by below way I can able to get response as well.

string sURL = "http://localhost:63024/PresidentsService.svc/presidents";
WebRequest wrGETURL;
wrGETURL = WebRequest.Create(sURL);
wrGETURL.Method = "GET";
wrGETURL.ContentType = @"application/xml; charset=utf-8";
HttpWebResponse webresponse = wrGETURL.GetResponse() as HttpWebResponse;
Encoding enc = System.Text.Encoding.GetEncoding("utf-8");
StreamReader loResponseStream = new StreamReader(webresponse.GetResponseStream(), enc);
string strResult = loResponseStream.ReadToEnd();
loResponseStream.Close();
webresponse.Close();
Response.Write(strResult);

So what is the issue? Please help me.

Code Location: https://onedrive.live.com/redir?resid=40B8798B80E2D2D4%21106

Answers (1)