从 FileStream 返回可序列化对象?

发布于 2024-10-09 15:35:08 字数 1671 浏览 0 评论 0原文

当谈到流式传输和序列化时,我有点陌生......但我想做的是让服务器上的 Upload 方法向客户端返回一个可序列化的对象(现在它是无效的)。

我有一个用 [Serialized] 装饰的公共类 ServiceResult,以及一个实现 IFileTransferService 的公共类 FileTransferService 该

[ServiceContract()]
public interface IFileTransferService
{
    [OperationContract(IsOneWay = false)]
    string Upload(FileTransferRequest request);
}

实现完成其工作,然后最后我创建并序列化该对象并尝试返回字符串

return ServiceResultSerializer.SerializeAnObject(result);

在客户端我使用此类调用此服务

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

我基本上采用此博客上找到的此项目: http://weblogs.asp.net/cibrax/archive/2007/08/29/sending-attachments-with-wcf.aspx

并试图让它返回一个值客户端调用者可以使用

我现在收到一条错误消息:

无法加载操作“Upload”,因为它具有 System.ServiceModel.Channels.Message 类型的参数或返回类型,或者具有 MessageContractAttribute 和其他不同类型参数的类型。使用 System.ServiceModel.Channels.Message 或带有 MessageContractAttribute 的类型时,该方法不得使用任何其他类型的参数。

我不知道这意味着什么:PI认为因为我正在尝试更改服务参数。

抱歉,如果我太笼统了 - 任何帮助将不胜感激。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暮年 2024-10-16 15:35:08

在我看来,您的 FileTransferRequest 类已应用了 MessageContractAttribute

由于您的输入参数具有 MessageContractAttribute,因此您的响应类型也应具有 MessageContractAttribute,而 String 则没有。尝试创建一个具有单个字符串类型属性的 FileTransferResponse 类,并将其用作返回类型。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文