【问题标题】:WCF method showing invalid parameters显示无效参数的 WCF 方法
【发布时间】:2010-08-30 20:23:44
【问题描述】:

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

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

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

DownloadFile(FileMetaData metadata, out stream outStream)

网络服务的完整代码如下:

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

请指教。

【问题讨论】:

    标签: c# .net wcf


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-28
      • 2011-04-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多