C# 无法隐式转换类型';WebService2.CustomServiceProxy.MemoryStream';至';System.IO.MemoryStream';

C# 无法隐式转换类型';WebService2.CustomServiceProxy.MemoryStream';至';System.IO.MemoryStream';,c#,web-services,C#,Web Services,我在服务器1上创建了以下方法: public System.IO.MemoryStream ms(string sessionID, int customerID) 在服务器2上,我通过以下方式向此方法发送参数: CustomService customService = new WebService2.CustomServiceProxy.CustomService(); System.IO.MemoryStream MS = customService.ms(s.SessionID, Cu

我在服务器1上创建了以下方法:

public System.IO.MemoryStream ms(string sessionID, int customerID)
在服务器2上,我通过以下方式向此方法发送参数:

CustomService customService = new WebService2.CustomServiceProxy.CustomService();
System.IO.MemoryStream MS = customService.ms(s.SessionID, Cust.Id);
CustomServiceProxy是指向服务器1的web引用的名称

因此,当我这样做时,我收到的信息是:

错误1无法将类型“WebService2.CustomServiceProxy.MemoryStream”隐式转换为“System.IO.MemoryStream”

有什么想法吗


谢谢你的帮助。

我首先想到的是演员阵容。大概是这样的:

System.IO.MemoryStream MS = (System.IO.MemoryStream)customService.ms(s.SessionID, Cust.ID);

不确定这是否行得通,但它就在那里。祝您好运

不要返回内存流,而是返回字节数组。您的web代理创建将有一些选项,如“使用现有类型”,这些选项将不会被选中。代理创建过程已重新创建了
MemoryStream
类。您可以通过更改代理生成的选项来避免这种情况。但正如Lasse所建议的,从这样的服务中,您应该返回一个字节数组,而不是
内存流。您可以使用
GetBuffer
方法从
MemoryStream
获取字节数组-@LasseV.Karlsen是正确的,您应该将内存流转换为字节数组并返回该数组。