Click here to Skip to main content
15,886,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,
I am trying to Run a WCF Service, but I am getting the error
"Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata"
I have mentioned the details about my service here.
I am using Entity Data Model to bind DataTables.

Code:
Iwarservice.cs:
C#
using System;
using System.Collections.Generic;
using System.Linq;

using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Data;

namespace WcfServiceApp
{
    public interface IWardService
    {
        [OperationContract]
        List<Gema_WardSecond> GetWard();
    }

    [DataContract]
    public class WardMaster
    {
        [DataMember]
        public int CompanyCode { get; set; }
        [DataMember]
        public int Yearcode { get; set; }
        [DataMember]
        public int Wardid { get; set; }
        [DataMember]
        public string WardName { get; set; }
        [DataMember]
        public string Remarks { get; set; }
        [DataMember]
        public int ActiveFlag { get; set; }
        [DataMember]
        public string CreatedBy { get; set; }
        [DataMember]
        public DateTime Createddate { get; set; }
        [DataMember]
        public DateTime ModifiedDate { get; set; }
    }

    [DataContract]
    public class WardMasterList
    {
        [DataMember]
        public List<WardMaster> Ward { get; set; }
    }
} ......


Wardservice.svc.cs
C#
using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;

namespace WcfServiceApp
{
    public class WardService : IWardService
    {
        public List<gema_wardsecond> GetWard()
        {
            WardConfig context = new WardConfig();
            var wardEntity = (from p
                                in context.Gema_WardSecond
                              select p).ToList();

            //if (wardEntity != null)
            //    return TranslateWardEntityToWardList(wardEntity);
            //else
            //    throw new Exception("Invalid ward id");
            return wardEntity;
        }
    }
}
Posted
v3
Comments
Show the web.config.

You're most likely missing the MEX binding from your configuration.

How to: Create a Service Endpoint in Configuration[^]

Pay attention to this bit:

XML
<endpoint address="mex">
binding="mexHttpBinding"
contract="IMetadataExchange" /></endpoint>
 
Share this answer
 
The error seems to be in the service configuration file.

You have to be declared in app.config:

XML
<endpoint address="mex">
        binding="mexHttpBinding"
        contract="IMetadataExchange" /></endpoint>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900