简体   繁体   English

使用WCF进行流传输限制

[英]Streamed transfer restrictions with WCF

According to the following guide at MSDN, any operations that use streamed transfers can only have one input/output parameter. 根据MSDN上的以下指南,使用流传输的任何操作只能具有一个输入/输出参数。

Link: http://msdn.microsoft.com/en-us/library/ms731913.aspx (see heading "Restrictions on Streamed Transfers") 链接: http : //msdn.microsoft.com/zh-cn/library/ms731913.aspx (请参阅标题“流传输限制”)

I'm using streamed transfers for a WCF service that lets clients/consumers upload files to it. 我正在为WCF服务使用流传输,该服务允许客户端/消费者将文件上传到其中。 The upload itself works fine, but I need a way of passing two more input parameters along with the Stream object: 'string filename' and 'int userid'. 上传本身可以正常工作,但是我需要一种与Stream对象一起传递两个输入参数的方法:“字符串文件名”和“ int用户ID”。

How would I go about doing this? 我将如何去做呢?

There´s something called headers that you can use in your datacontract: 您可以在数据合同中使用一种称为标头的东西:

Example of the interface: 接口示例:

[ServiceContract]
public interface IFile
{
   [OperationContract]
   Stream DownloadFile(int fileid);

   [OperationContract]
   bool UploadFile(FileUploadMessage request);
}

Put this in a separate file: 将其放在单独的文件中:

[MessageContract]
public class FileUploadMessage
{
[MessageHeader(MustUnderstand = true)]
public int MyInt {get;set;

[MessageHeader(MustUnderstand = true)]
public string MyString {get;set;

[MessageBodyMember(Order = 1)]
public System.IO.Stream FileByteStream {get;set;}
}

I have a somewhat similar problem. 我有一个类似的问题。 I created a test project and used a post I found to successfully create a wcf service call it from another project. 我创建了一个测试项目,并使用我发现的成功创建了wcf服务的帖子从另一个项目调用了它。 I have a solution and the two web projects. 我有一个解决方案和两个Web项目。 One project call the service in the other project using a service reference. 一个项目使用服务引用在另一个项目中调用服务。 I had the ServiceContract and the message contract in the interface file generated by creating a wcf service (the file that start with "I"). 我通过创建wcf服务(以“ I”开头的文件)生成的接口文件中有ServiceContract和消息协定。 All of this worked fine. 所有这些都很好。 Then I went to our company's main project. 然后我去了我们公司的主要项目。 It has a main web project that hosts two silverlight project. 它有一个主要的Web项目,托管两个Silverlight项目。 However the web project is not really a project but started out life as a website with no project at all. 但是,Web项目并不是真正的项目,而是从根本没有项目的网站开始的。 I have assumed that adding the two silverlight projects to the website probably created a solution for all three projects. 我以为将两个Silverlight项目添加到网站可能为所有三个项目创建了一个解决方案。 However I'm not certain how vs2010 sees the main website which I will assume has no pointers to any files as a "real" project would. 但是我不确定vs2010如何看待主网站,我将假定它没有像“真实”项目那样指向任何文件的指针。 What happened was when I created the wcf service in the main website and put the ServiceContract and MessageContract into the interface file I got the "interfaces cannot declare types" messge regarding the MessageContract and its child classes. 发生了什么事,是当我在主网站上创建wcf服务并将ServiceContract和MessageContract放入接口文件时,我得到了有关MessageContract及其子类的“接口无法声明类型”消息。 I'm trying to follow your advice onthis post by taking the MessageContract and putting it into another file but I'm not sure what type of file. 我正在尝试通过将MessageContract放入另一个文件中来遵循您对本文的建议,但是我不确定哪种文件类型。 I tried putting the Message contract into a class (cs file). 我尝试将Message合同放入一个类(cs文件)中。 However the ServiceContract refers to classes in the MessageContract and the ServiceContract is no longer seeing the classes in the MessageContract even though they are public. 但是,ServiceContract引用了MessageContract中的类,并且即使它们是公共的,ServiceContract也不再看到MessageContract中的类。 What type of file should I use to separate the Message contract from the ServiceContract? 我应该使用哪种类型的文件将Message合同与ServiceContract分开?

Thanks, Fig 谢谢,无花果

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

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