0

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

I have searched long and hard but found nothing that helped yet. Where I wrong? I really do not know what to do. I wrote all the details below. I've tried and did not succeed.

my code :

[ServiceContract]

    public interface IUsersService
    {
        [OperationContract]
        void DoWork();

        [OperationContract]
        List<User> GetUsers();
    }




 public class UsersService : IUsersService
    {
        public void DoWork()
        {

        }

        public List<User> GetUsers()
        {
            var users=new List<User>();
            var sqlConnection =
                new SqlConnection(conString);
            var sqlDataAdapter=new SqlDataAdapter("select * from users",sqlConnection);

            var dt = new DataTable();

            sqlDataAdapter.Fill(dt);

            foreach (DataRow dataRow in dt.Rows)
            {
                users.Add(new User(dataRow["Name"].ToString()));
            }

            return users;
        }
    }

    public class User
    {
        public string UserName { get; set; }

        public User(string name)
        {
            UserName = name;
        }
    }

web config :

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="JuventusNewsWebService.UsersServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="JuventusNewsWebService.UsersServiceBehavior"
          name="JuventusNewsWebService.UsersService">
        <endpoint address="" binding="basicHttpBinding" contract="JuventusNewsWebService.IUsersService">
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
  </system.serviceModel>

error :

> Error: Cannot obtain Metadata from
> http://lo cal host:31842/UsersService.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
> http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange
> Error    URI: http://localhost:31842/UsersService.svc    Metadata
> contains a reference that cannot be resolved:
> 'http://localhost:31842/UsersService.svc'.    Content Type
> application/soap+xml; charset=utf-8 was not supported by service
> http://localhost:31842/UsersService.svc.  The client and service
> bindings may be mismatched.    The remote server returned an error:
> (415) Cannot process the message because the content type
> 'application/soap+xml; charset=utf-8' was not the expected type
> 'text/xml; charset=utf-8'...
Aron
  • 15,464
  • 3
  • 31
  • 64
Football-Is-My-Life
  • 1,407
  • 7
  • 18
  • 35

2 Answers2

0

could It be you are missing host with in services :

 <services>
      <service name="WcfServiceLibrary1.UsersService">
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/UsersService/" />
          </baseAddresses>
        </host>
....
  </service>
    </services>
hanz
  • 139
  • 7
0

Generally you don't need to define the baseAddress if you host the service in IIS which takes care of this.

While the suggestion from the error message might be working, however, please be aware that the solution is for legacy Web service. For WCF, you don't need that setting.

For more detail, you have have a look this CodeProject article. http://www.codeproject.com/Articles/627240/WCF-for-the-Real-World-Not-Hello-World

For your problem, please check it the example codes particularly app.config deal with relative url and activate the service.

ZZZ
  • 2,752
  • 2
  • 25
  • 37