简体   繁体   English

在WCF服务中传递用户定义的参数会导致问题

[英]passing user defined parameters in WCF service causing problems

I am creating a wcf self hosted service. 我正在创建WCF自托管服务。 I am using UriTemplate class to customize the urls to methods. 我正在使用UriTemplate类自定义方法的URL。 the code snippet is given below 该代码段如下

 public interface ISelfService
    {
        [WebInvoke(Method = "POST", UriTemplate = "ack/{errorcode}/{uniquefileid}")]
        [OperationContract]
        void Ack(ErrorCode errorcode, string uniquefileid);

       [WebInvoke(Method = "POST", UriTemplate = "filechanged/{metainfo}")]
       [OperationContract]
       void FileChanged(MetaInformation metainfo);

     }

Whenever i run this program i am getting the following error 每当我运行此程序时,都会出现以下错误

Operation 'FileChanged' in contract 'ISelfHostService' has a query variable named 'metainfo' of type 'Natash.Common.MetaInformation', but type 'Natash.Common.MetaInformation' is not convertible by 'QueryStringConverter'. 合同“ ISelfHostService”中的操作“ FileChanged”具有一个名为“元信息”的查询变量,其类型为“ Natash.Common.MetaInformation”,但类型“ Natash.Common.MetaInformation”不能由“ QueryStringConverter”转换。 Variables for UriTemplate query values must have types that can be converted by 'QueryStringConverter' UriTemplate查询值的变量必须具有可以由“ QueryStringConverter”转换的类型

Can any one tell me why is this happening? 谁能告诉我为什么会这样吗?

And, I have not made any modification to the web.config file. 而且,我尚未对web.config文件进行任何修改。 Do i need to make any modification there? 我需要在那里进行任何修改吗?

MetaInformation is defined as follows MetaInformation定义如下

[DataContract]
    public struct MetaInformation
    {
        [DataMember]
        public string Author { get; set; }
        [DataMember]
        public string tags { get; set; }
        [DataMember]
        public string categories { get; set; }
        [DataMember]
        public string description { get; set; }
}

try this 尝试这个

public interface ISelfService{

  [OperationContract] [WebInvoke(Method = "POST", UriTemplate = "/ack?errorcode={errorcode}&uniquefileid={uniquefileid}")] void Ack(ErrorCode errorcode, string uniquefileid); [OperationContract] [WebInvoke(Method = "POST", UriTemplate = "/filechanged")] void FileChanged(MetaInformation metainfo);} 

From the message you posted it sounds like there are 2 definitions for the MetaInformation class ( Gettrix.Common.MetaInformation & Natash.Common.MetaInformation ). 从您发布的消息中,听起来好像MetaInformation类有2个定义( Gettrix.Common.MetaInformationNatash.Common.MetaInformation )。

It could be that both are in scope for WCF to see when instantiating the service. 实例化服务时,WCF可能会看到两者。 If so, it might think that the one that does not have a DataContract attribute (probably Natash.Common.MetaInformation ) is what you are reffering to and therefore would not be usable for data transfer within the service. 如果是这样,它可能会认为您没有使用DataContract属性(可能是Natash.Common.MetaInformation ),因此不能用于该服务内的数据传输。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM