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'...