字节数组作为out参数不能识别
-
19-08-2019 - |
题
我有其返回的字节数组的呼叫者的webmethod工作:
public byte[] DownloadPDF(string URI)
我不得不改变此返回另一个输出(字符串)。所以,我决定现在返回void和具有这样3个参数完全改变方法:
public void DownloadFile(string URI, out byte[] docContents, out string returnFiletype)
我的Web服务编译正确,但我怀疑的东西是错误的第二个参数(即字节数组),因为当我“添加Web引用”,并建立我的代理类,方法只有两个参数,而不是3):
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/DownloadFile", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[return: System.Xml.Serialization.XmlElementAttribute("docContents", DataType="base64Binary")]
public byte[] DownloadFile(string URI, out string returnFiletype) {
object[] results = this.Invoke("DownloadFile", new object[] {
URI});
returnFiletype = ((string)(results[1]));
return ((byte[])(results[0]));
}
我不明白为什么我的第二个参数,字节数组,被忽略,但它似乎是问题的根源。
这当然打乱了我在Web客户端应用程序,我在编译的时候得到一个错误信息:
No overload for method 'DownloadFile' takes '3' arguments
下面是在web客户端,其中我需要通过3个参数的代码:
myBrokerASMXProxy.ASMXProxy.FileService client = new myASMXProxy.ASMXProxy.FileService();
byte[] fileDataBytes;
string fileType;
client.DownloadFile(URI, fileDataBytes, fileType);
我想改变回返回一个字节数组,并添加只是一个单一的“out”参数,但我想我应该问你的专家关于这一点,在一般情况下,什么是处理多个输出要求的最佳实践。
解决方案
为什么不是你尝试把这个签名:
public bool DownloadFile(string URI, out byte[] docContents, out string returnFiletype)
要看看会发生什么?我同意乔恩斯基特,但你仍然可以能够与操作的结果。
返回一个布尔其他提示
的字节数组没有被忽略 - 它被投入作为返回类型,而不是。我不知道为什么它这样做,但它更有意义在我看来。我不会在一个void方法使用out参数。我怀疑代理生成器只是需要与输出参数的任何方法和使第一一成返回类型。
不隶属于 StackOverflow