开发者

Return Serializable object from FileStream?

开发者 https://www.devze.com 2023-02-01 16:33 出处:网络
I\'m a little green when it comes to streaming and serialization...but what I want to do is make the Upload method on the server return a serializable object to the client (it is void right now).

I'm a little green when it comes to streaming and serialization...but what I want to do is make the Upload method on the server return a serializable object to the client (it is void right now).

I have a public class ServiceResult that I decorate with [Serializable], and a public class FileTransferService that implements IFileTransferService

[ServiceContract()]
public interface IFileTransferService
{
    [OperationContract(IsOneWay = false)]
    string Upload(FileTransferRequest request);
开发者_如何转开发}

The implementation does its thing, and then at the end I create and serialize the object and try to return the string

return ServiceResultSerializer.SerializeAnObject(result);

On the client side I call this service using this class

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName = "IFileTransferService")]
public interface IFileTransferService
{

    // CODEGEN: Generating message contract since the wrapper name (FileTransferRequest) of message FileTransferRequest does not match the default value (Upload)
    [System.ServiceModel.OperationContractAttribute(IsOneWay = false, Action = "http://tempuri.org/IFileTransferService/Upload")]
    string Upload(FileTransferRequest request);
}

I'm basically taking this project found on this blog: http://weblogs.asp.net/cibrax/archive/2007/08/29/sending-attachments-with-wcf.aspx

And trying to make it return a value that the client caller can use

I get an error right now that says:

The operation 'Upload' could not be loaded because it has a parameter or return type of type System.ServiceModel.Channels.Message or a type that has MessageContractAttribute and other parameters of different types. When using System.ServiceModel.Channels.Message or types with MessageContractAttribute, the method must not use any other types of parameters.

Which i have no idea what it means :P I think because I'm trying to change the Service parameters.

Sorry if I'm being too general - any help would be greatly appreciated.


It sounds to me like your FileTransferRequest class has MessageContractAttribute applied to it.

Since your input parameter has MessageContractAttribute, your response type should also have MessageContractAttribute, which String doesn't. Try creating a FileTransferResponse class that has a single string-type property, and use that as your return type.

0

精彩评论

暂无评论...
验证码 换一张
取 消