2010-08-30 56 views
0

我有一个WCF服务,在它我有需要MessageContracts作为输入参数,并返回一个MessageContract作为输出参数的方法。请在下面找到WCF方法表示无效参数

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

方法认定中但是,当我创建客户端上的代理,并尝试访问此方法我得到的方法的不同定义。下面是我所看到的,当我尝试访问该方法的Web服务的

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

请指教。

回答

1

默认情况下,代理不使用消息合同,所以当你的服务生成代理使用消息协定它解开他们和包含的数据合同作为操作参数和输出值。如果您想在代理上使用邮件合同,厚在Visual Studio中添加服务引用时,始终生成邮件合同。对于svcutil使用/ mc开关。

+0

你是绝对正确的。非常感谢 – Amit 2010-08-30 12:29:23