ObservableCollection返回类型WCF元数据错误。 (无法获取元数据信息) [英] ObservableCollection return Type WCF meta data Error. (Cannot obtain metadata information)

查看:97
本文介绍了ObservableCollection返回类型WCF元数据错误。 (无法获取元数据信息)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我在使用svcutil生成元数据时遇到问题,wcf主机客户端也无法获取元数据信息。当我返回ObservableCollection< t>时会发生此问题来自WCF运营。让我解释一下问题。





我创建了自定义GenericCollection< t>哪个继承自ObservableCollection< t> ;.



注意:我认为这只是GenericCollection中的问题,因为当我使用List<>而不是GenericCollection,我面临问题。



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;
           }
       }





我创建了一个wcf服务,如下所示





I created a wcf service as given below

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

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







现在当我使用WCF主​​机客户端调用(调试)服务时,我收到以下错误< br $>




错误:无法从http:// localhost:8733 / ISetupService / mex获取元数据如果这是Windows(R )您有权访问的Communication Foundation服务,请检查您是否已在指定地址启用元数据发布。有关启用元数据发布的帮助,请参阅MSDN






svcutil.exe 给下面的错误



DataContract类型为System.Collections.ObjectModel.Collection`1 [Business.DataContracts.LoginUserInfo,<<&Assembly; Assembly Information>> ]

无法添加到DataContractSet,因为类型

'System.Collections.ObjectModel.Collection`1 [Business.DataContracts.LoginUserInfo,<<&Assembly; Assembly Information>> ]'

在命名空间''中具有相同的数据协定名称'arrayofLoginUserInfo'已经存在且合同不相等





我想与你分享的最后一件事是配置文件。






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>

推荐答案

从GenericCollection< t>中删除DataContract属性。





但我仍然没有找到任何理由。现在任何方式服务都没问题,元数据也没问题
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


对于你的元数据问题。试试下面的一个。



发布元数据使用配置文件的服务:



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



使用代码发布服务的元数据:



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



SOF:



HTTP:// stackov erflow.com/questions/1546716/where-to-enable-metadata-is-enabled-in-config [ ^ ]



我希望这会有所帮助给你。
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.


这篇关于ObservableCollection返回类型WCF元数据错误。 (无法获取元数据信息)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆