Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my wcf contains generic list and its having 3 functions and 3 return types 1-generic list,2-dataset,3-bool type

without any binding by default its working properly.. but when am trying to add wsHttpBinding its showing error message like this...

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

my requirement is i wana use secure binding for this data(return data like generic list,dataset,bool) in transport level and message level..

ppl can u help me out from this problem

my total code here

IService1.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;
using System.Data.SqlClient;

namespace samplewcf
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        List<result> personaldata(string userid);
        //[OperationContract]
        //void add(result1 s);
        [OperationContract]
        DataSet gridbind();

        [OperationContract]
        bool fun();

        // TODO: Add your service operations here
    }


    // Use a data contract as illustrated in the sample below to add composite types to service operations.
    [DataContract]
    public class result
    {
        [DataMember]
        public int Nofid
        {
            get;
            set;
        }
        [DataMember]
        public string Name
        {
            get;
            set;
        }
        [DataMember]
        public bool Gender
        {
            get;
            set;
        }
        [DataMember]
        public char Status
        {
            get;
            set;
        }
    }
    
   
}


Service.svc.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;
using System.Data.SqlClient;
using System.Configuration;

namespace samplewcf
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    public class Service1 : IService1
    {
        List<result> res = new List<result>();
        public List<result> personaldata(string userid)
        {

           //am using some data source.. for this data but.. its ok with values 1,person,true,A

            result rs = new result();
            rs.Nofid = 1;
            rs.Name = "person";
            rs.Gender = true;
            rs.Status = 'A';
            res.Add(rs);
            //rls.Add(rs);
            return res;        

        }
        public DataSet gridbind()
        {          //here am using some data source..  u can user any data that store in dataset
            DataSet ds = new DataSet();
            return ds;          

        }
        public bool fun()
        {
            return true;
        }
    }
}


web.config file

C#
<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="samplewcf.Service1"
        behaviorConfiguration="samplewcf.Service1Behavior">

        <!-- Service Endpoints -->
        <endpoint address="ServiceFile.svc" binding="wsHttpBinding" contract="samplewcf.IService1">
        </endpoint>
        <endpoint address="Service1.svc" binding="wsHttpBinding"   contract="samplewcf.IService1"/>


        <endpoint address="mex" binding="mexHttspBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpsGetEnabled="True" 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"/>
        </behavior>
        
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <wsHttpBinding>
        <binding name="TransportSecurity">
          <security mode="Transport">
            <transport clientCredentialType="None"></transport>
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
  
</configuration>




so ppl here my all code.. just check it..i wana this wcf service in wsBttpBinding with secure binding and ppl am waiting for ur valuable answers
Posted
Updated 8-May-13 20:36pm
v6
Comments
Post your web.config code here by clicking on "Improve question" link.
Balimusi 8-May-13 10:02am    
Try adding the baseAddress; for instance,
<host>
<baseAddresses>
<add baseaddress="http://localhost:8733/Design_Time_Addresses/WcfService1/Service1/">
</baseAddresses>
</add>
</host>

1 solution

You need to provide the endpoint address inside the service tag.
You can provide the absolute or relative Url.

But providing a relative Url is the best method, because when you host that in IIS, the absolute Url may change, but the relative will be the same and you don't need to change that again.

So, if the web.config and the service .svc file are at the same directory, then directly add the filename in the address like below.
XML
<endpoint address="ServiceFile.svc" binding="wsHttpBinding" contract="WcfService1.IService1">
</endpoint>

So, you need to provide the correct relative address according of the Service file.

Let me know it works or not.

[Update]

1. Include Service Behaviour
You have added Service like below in web.config.
XML
<service name="samplewcf.Service1"
        behaviorConfiguration="samplewcf.Service1Behavior">

But you have to forgot to include this behavior inside serviceBehaviors tags.
That is like below (Just add this name to the existing behavior)...
XML
<serviceBehaviors>
        <behavior name="samplewcf.Service1Behavior">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpsGetEnabled="True" 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"/>
        </behavior>
</serviceBehaviors>


2. Typo mistake in endpoint binding
XML
<service name="samplewcf.Service1"
        behaviorConfiguration="samplewcf.Service1Behavior">
 
        <!-- Service Endpoints -->
        <endpoint address="ServiceFile.svc" binding="wsHttpBinding" contract="samplewcf.IService1">
        </endpoint>
        <endpoint address="Service1.svc" binding="wsHttpBinding"   contract="samplewcf.IService1"/>
 
        <endpoint address="mex" binding="mexHttspBinding" contract="IMetadataExchange"/>
</service>

This should be mexHttpBinding removing extra "s".
And keep only the required endpoint.

So, that will finally look like below.
XML
<service name="samplewcf.Service1"
        behaviorConfiguration="samplewcf.Service1Behavior">
 
        <!-- Service Endpoints -->
        </endpoint>
        <endpoint address="Service1.svc" binding="wsHttpBinding"   contract="samplewcf.IService1"/> 

        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>


Please correct your code as suggested, it should work fine. It is working fine at my end.
Let me know if you face issues again.


Note - I just resolved this issue, I have not checked the functionality of the Service functions. You need to check and test.

Thanks...
 
Share this answer
 
v2
Comments
ntitish 9-May-13 0:04am    
sorry sir.. its not working once again its showing same error

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

can u ppl tell this error meaning and why this error coming so that i can try to fix

in my wcf service returning generic list,dataset,bool.... with wsHttpBinding
Ok. Now do one thing... Just zip your project and upload in Ge.tt or Dropbox and send me the link here. I will download and try to remove the error. Please do it. Waiting for your reply.

ntitish 9-May-13 2:32am    
actually i dint know GE.tt and Dropbox... soo i post my total code here.. so its available to all other ... plz refer my code above
Ok... I will reply you again.
ntitish 9-May-13 6:55am    
hi ... any possibilities ... to resolve this error

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