Click here to Skip to main content
15,918,125 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi All,

I face problem in generating Metadata using svcutil, also wcf host client is unable to obtain meta data information. This problem occur when I return ObservableCollection<t> from WCF Operation. Let me explain problem.


I have created custom GenericCollection<t> which Inherits from ObservableCollection<t>.

Note: I think this only issue in GenericCollection because when i use List<> instead of GenericCollection, I face issue.

C#
[Serializable]
   [System.Runtime.Serialization.DataContractAttribute(Namespace = "Business.DataContracts", Name = "GenericCollection_{0}")]
   public class GenericCollection<T> : ObservableCollection<T>, IDisposable, ICloneable
   {
       private ObservableCollection<T> source;

       public GenericCollection()
           : base() { source = new ObservableCollection<T>(); }


       [System.Runtime.Serialization.DataMember]
       public GenericCollection<T> OriginalDataSource
       {
           get
           {
               GenericCollection<T> result = new GenericCollection<T>();
               if (source != null)
               {
                   foreach (var info in source)
                       result.Add(info);
               }

               return result;
           }
       }


I created a wcf service as given below

C#
[OperationContract]
        GenericCollection<LoginUserInfo> ReadUserInfo(int request);

//Where LoginUserInfo is Simple DataContract having basic fields i.e. Login_Name, ID, Active



Now when I invoke (debug) service using WCF host client I get following error


Error: Cannot obtain Metadata from http://localhost:8733/ISetupService/mex 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



svcutil.exe give bellow error

DataContract for type "System.Collections.ObjectModel.Collection`1[Business.DataContracts.LoginUserInfo, <<Assembly Information>>]
cannot be added to DataContractSet since type
'System.Collections.ObjectModel.Collection`1[Business.DataContracts.LoginUserInfo, <<Assembly Information>>]'
with the same data contract name 'arrayofLoginUserInfo' in namespace '' is already present and the contracts are not equivalent


Last thing I wanna share with you is config file.

HTML
<services>
      <service name="Business.Service.Services.SetupService">
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:8733/ISetupService/" />
          </baseAddresses>
        </host>
        
        <endpoint address="" binding="basicHttpBinding" contract="Business.Service.ISetupService">
           
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
         
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
Posted

remove DataContract Attribute from GenericCollection<t>.


But still I have not find any reason why. Any way service is ok now, and no problem with metadata
 
Share this answer
 
Comments
Sampath Lokuge 22-Jul-13 9:08am    
Glad to hear that you found a solution.Then accept your solution as a answer.It will help for someone else in future.
For your metadata issue.Try below one.

Publish Metadata for a Service Using a Configuration File :

http://msdn.microsoft.com/en-us/library/ms734765(v=vs.100).aspx[^]

Publish Metadata for a Service Using Code :

http://msdn.microsoft.com/en-us/library/aa738489(v=vs.100).aspx[^]

SOF:

http://stackoverflow.com/questions/1546716/where-to-enable-metadata-is-enabled-in-config[^]

I hope this will help to you.
 
Share this answer
 
Comments
M.Kamran Asim 22-Jul-13 0:54am    
Dear Sampath,

Thanks for your valuable information. I think here is not metadata publish issue. Thing which create problem is GenericCollection<t> Class. When I use List or ObservableCollection instead of GenericCollection<t>, metadata publish successfully.

I resolve issue by removing DataContract attribute from GenericCollection<t>.
I dont know why i get problem, when applying DataContract attribute on GenericCollection<t>.


For your information, I want to clear return type

Actual return type of mentioned operation is ResponseObject<genericcollection<userinfo>>

Where ResponseObject is generic and has DataContractAtrribute, with ResultSet is Datamember of Generic type like

[DataContract]
public ResponseObject<t>
{

[DataMember]
public T ResultSet
{get;set;}
}


So has issue due to ResponseObject<> has DataContract also GenericCollection<t> has DataContract. ??

Once again still I have not find any reason, why metadata failed on applying DataContract on GenericCollection<t>

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