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
internal List
{
get
{
// If there aren't any presidents in our list, populate with samples and return
_presidents = _presidents ?? new List
return _presidents;
}
}
public List
{
return presidents;
}
#endregion // IPresidentsService Methods
}
}
Service Web.Config:
Client Web.Config:
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
avijit goraiPosted Sep 28, 2014, 2:25 PM
Actually I was calling REST service by SOAP method which is not supported by REST. Need to call it only by HTTP supported request.
PresidentsServiceClient client = new PresidentsServiceClient(); //This only supported by SOAP request and not supported by REST call
President[] result1 = client.GetAllPresidentsXml();
This way I will never consume a REST service.
It was my bad that I was not aware of this fact.