سؤال

According to the following guide at MSDN, any operations that use streamed transfers can only have one input/output parameter.

Link: http://msdn.microsoft.com/en-us/library/ms731913.aspx (see heading "Restrictions on Streamed Transfers")

I'm using streamed transfers for a WCF service that lets clients/consumers upload files to it. 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'.

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. I have a solution and the two web projects. 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"). 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. However the web project is not really a project but started out life as a website with no project at all. I have assumed that adding the two silverlight projects to the website probably created a solution for all three projects. 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. 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. 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. I tried putting the Message contract into a class (cs file). 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. What type of file should I use to separate the Message contract from the ServiceContract?

Thanks, Fig

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top