Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata RRS feed

  • Question

  • hello, i am using a wcf service but i am suffering from an error 

    Error: Cannot obtain Metadata from http://localhost:21478/Service1.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address.  For help enabling metadata publishing, please refer to the MSDN documentation at Exchange Error    URI: http://localhost:21478/Service1.svc    Metadata contains a reference that cannot be resolved: 'http://localhost:21478/Service1.svc'.    There was no endpoint listening at http://localhost:21478/Service1.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.    Unable to connect to the remote server    No connection could be made because the target machine actively refused it GET Error    URI: http://localhost:21478/Service1.svc    There was an error downloading 'http://localhost:21478/Service1.svc'.    Unable to connect to the remote server    No connection could be made because the target machine actively refused it

    my web.config file

    <?xml version="1.0"?>
        <compilation debug="true" targetFramework="4.0" />
          <!-- Note: the service name must match the configuration name for the service implementation. -->
          <service name="MyNamespace.MyServiceType" behaviorConfiguration="MyServiceTypeBehaviors" >
            <!-- Add the following endpoint.  -->
            <!-- Note: your service must have an http base address to add this endpoint. -->
            <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
            <behavior name="MyServiceTypeBehaviors">
              <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
              <serviceMetadata httpGetEnabled="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"/>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
        <modules runAllManagedModulesForAllRequests="true"/>
    My iservice1.cs

    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.SqlClient;
    using System.Data;
    namespace WcfService2
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
        public interface IService1
            string InsertUserDetails(UserDetails userInfo);
            DataSet SelectUserDetails();
            bool DeleteUserDetails(UserDetails userInfo);
            DataSet UpdateUserDetails(UserDetails userInfo);
            void UpdateRegistrationTable(UserDetails userInfo);
            // TODO: Add your service operations here
        // Use a data contract as illustrated in the sample below to add composite types to service operations.
        public class UserDetails
            string username;
            string password;
            public string UserName
                get { return username; }
                set { username = value; }
            public string Password
                get { return password; }
                set { password = value; }

    Service1.svc file

    <%@ ServiceHost Language="C#" Debug="true" Service="WcfService2.Service1" CodeBehind="Service1.svc.cs" %>

    Friday, February 14, 2014 9:47 AM


  • Hi,

    From the code you provided, I know that your service name will be "WcfService2.Service1", but in your service config file the sever name is "MyNamespace.MyServiceType", please try to modify the server name as below:

     <service name="WcfService2.Service1" behaviorConfiguration="MyServiceTypeBehaviors" >

    Best Regards,
    Amy Peng

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, February 17, 2014 3:07 AM