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.
[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
[OperationContract]
GenericCollection<LoginUserInfo> ReadUserInfo(int request);
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.
<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>