【问题标题】:Streaming webservice call in flex在 flex 中流式传输 Web 服务调用
【发布时间】:2013-01-16 19:30:37
【问题描述】:

我正在尝试在将信息发送到 .NET wcf SOAP Web 服务的 flex/air 应用程序中创建文件上传。文件上传还必须有进度指示事件。该服务使用 Stream 作为 MessageBodyMember 以允许流式上传。我的输入看起来有点像这样:

[MessageContract]
public class SendFileRequestMessage : IDisposable
{
    public string UserName;

    [MessageBodyMember(Order = 1)]
    public Stream FileData;
}

服务看起来像这样:

public interface IFileTransferService
{
    [OperationContract]
    SendFileResponseMessage SendFile(SendFileRequestMessage request);
}

现在,当我在 VS2010 中创建代理类时,我得到了 FileData 的 Stream 对象。如果我在 Flash Builder 4.7 中执行相同操作,则 FileData 被解释为 ByteArray。我已经在我的客户端中查看了 FileUpload 和 UrlLoader,但我无法设置正文成员。我的动作脚本现在看起来像这样 不工作

var dataToSave:XML = <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:q0="http://mystuff/uploadservice/v1"><soapenv:Body><q0:SendFile/></soapenv:Body></soapenv:Envelope>

            var request:URLRequest = new URLRequest("http://localhost:31454/Uploadhandler.svc");
            request.requestHeaders = new Array(new URLRequestHeader("SOAPAction", "http://mystuff/uploadservice/v1/IFileTransferService/SendFile"));
            request.data = dataToSave;
            request.contentType = "text/xml; charset=utf-8";

            request.method = URLRequestMethod.POST;

            var loader:URLLoader = new URLLoader();
            loader.load(request);

那么如何将流文件从 flex 上传到soap服务呢?任何帮助将不胜感激。

【问题讨论】:

  • 我的猜测是dataToSave必须是base64编码的。
  • 但是 dataToSave 现在是我的肥皂信息。我如何让它流式传输数据?就像动作脚本中的 fileUpload 控件...
  • 糟糕...抱歉。没有仔细阅读。发布了一个答案,因为它太大而无法评论。

标签: apache-flex soap actionscript upload urlloader


【解决方案1】:

我不熟悉 .NET SOAP 模型,但如果它期望文件数据的标准 http 内容配置,您可以尝试获取文件的 FileReference 对象,然后在其上传方法中传递您的 URLRequiest。在你的情况下,这可能是这样的

        ... Create class level variable ...
        var fr:FileReference = new FileReference();

        ... Obtain file reference somewhere ...
        //Set handlers for Filereference events 
        fr.browse(); //Obtain actual file reference  


        ... Somewhere in selectHandler chain....

        var dataToSave:XML = <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:q0="http://mystuff/uploadservice/v1"><soapenv:Body><q0:SendFile/></soapenv:Body></soapenv:Envelope>

        var request:URLRequest = new URLRequest("http://localhost:31454/Uploadhandler.svc");
        request.requestHeaders = new Array(new URLRequestHeader("SOAPAction", "http://mystuff/uploadservice/v1/IFileTransferService/SendFile"));
        request.data = dataToSave;
        request.contentType = "text/xml; charset=utf-8";
        request.method = URLRequestMethod.POST;

        //Do POST
        fr.upload(request);

Documentation 包含使用 FileReference 的示例。

【讨论】:

  • 嗨,大卫,感谢您的帮助。我现在收到来自服务的错误消息:“HTTP/1.1 415 无法处理消息,因为内容类型为 'multipart/form-data;边界=---------GI3Ij5Ij5ei4ae0Ij5ei4KM7ae0ei4' 不是预期的类型'text/xml;字符集=utf-8'。'我会尝试修复它并发布任何进展..
  • 仍在苦苦挣扎。看来我的服务只能接受 text/xml...
  • 嗯,在我的记忆深处暗示,FileRefenence 的内容类型也不能更改。我相信必须手动构造 HTTP 请求。
  • 你的意思是urlloader吗?我认为进度事件不再像此处所示forums.adobe.com/message/2902327 那样工作,除非您执行单独的请求...
  • 是的,我想到了 Urlloader。进度事件可能是问题。但是你真的需要进度条吗?一些繁忙的游标和超时定时器一起使用能满足你的需求吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多