从 FileStream 返回可序列化对象?
当谈到流式传输和序列化时,我有点陌生......但我想做的是让服务器上的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,您的
FileTransferRequest
类已应用了MessageContractAttribute
。由于您的输入参数具有
MessageContractAttribute
,因此您的响应类型也应具有MessageContractAttribute
,而String
则没有。尝试创建一个具有单个字符串类型属性的FileTransferResponse
类,并将其用作返回类型。It sounds to me like your
FileTransferRequest
class hasMessageContractAttribute
applied to it.Since your input parameter has
MessageContractAttribute
, your response type should also haveMessageContractAttribute
, whichString
doesn't. Try creating aFileTransferResponse
class that has a single string-type property, and use that as your return type.