WCF 方法显示无效参数 [英] WCF method showing invalid parameters

查看:31
本文介绍了WCF 方法显示无效参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 WCF 服务,其中我有一个方法,该方法将 MessageContracts 作为输入参数并返回 MessageContract 作为输出参数.请在下面找到方法定义

I have a WCF service, in it i have a method that takes a MessageContracts as input parameter and returns a MessageContract as out parameter. Please find the method defination below

[OperationContract(IsOneWay = false)]
FileDownloadReturnMessage DownloadFile(FileDownloadMessage request);

但是当我在客户端上创建代理并尝试访问此方法时,我得到了该方法的不同定义.以下是我尝试访问该方法时看到的内容

But when i create the proxy on the client and try to access this method i get a different definition of the method. Below is what i see when i try to access the method

DownloadFile(FileMetaData metadata, out stream outStream)

Web 服务的完整代码如下:

Complete code of the web service is below :

[ServiceContract(Namespace = "http://schemas.acme.it/2009/04/01")]
public interface IFileTransferService
{
    [OperationContract(IsOneWay = false)]
    FileDownloadReturnMessage DownloadFile(FileDownloadMessage request);

   [OperationContract()]
   string HellowWorld(string name);

}

[MessageContract]
public class FileDownloadMessage
{
    [MessageHeader(MustUnderstand = true)]
    public FileMetaData FileMetaData;
}

[MessageContract]
public class FileDownloadReturnMessage
{
    public FileDownloadReturnMessage(FileMetaData metaData, Stream stream)
    {
        this.DownloadedFileMetadata = metaData;
        this.FileByteStream = stream;
    }

    [MessageHeader(MustUnderstand = true)]
    public FileMetaData DownloadedFileMetadata;
    [MessageBodyMember(Order = 1)]
    public Stream FileByteStream;
}


[DataContract(Namespace = "http://schemas.acme.it/2009/04/01")]
public class FileMetaData
{
    public FileMetaData(string [] productIDs, string authenticationKey)
    {
        this.ids = productIDs;
     this.authenticationKey= authenticationKey;
    }

    [DataMember(Name = "ProductIDsArray", Order = 1, IsRequired = true)]
    public string[] ids;
    [DataMember(Name = "AuthenticationKey", Order = 2, IsRequired = true)]
    public string authenticationKey;
}

请指教.

推荐答案

默认情况下,代理不使用消息契约,因此当您使用消息契约为服务生成代理时,它会解开它们并使用包含数据契约作为操作参数和输出值.如果要在代理上使用消息契约,在 Visual Studio 中添加服务引用时总是生成消息契约.对于 svcutil 使用/mc 开关.

By default proxy doesn't use message contracts so when you generate proxy for service using message contracts it unwraps them and containing data contracts are used as operation parameters and output values. If you want to use message contracts on proxy, thick Always generate message contracts when adding service reference in Visual studio. For svcutil use /mc switch.

这篇关于WCF 方法显示无效参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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