2010-08-30 57 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