0

我正在尝试实现一项服务,该服务将允许用户从 Windows Phone 7 客户端(类似于 youtube)观看视频并将其上传到 WCF 服务。现在,我有了将视频文件 (.wmv) 发送到客户端的服务的基本实现,该客户端具有 Silverlight 框架的 MediaElement 实现(与同一类的 .NET 实现有一些差异)。现在,每当我尝试在客户端本地播放视频时,都会收到 SecurityException is unhandled 错误。当我尝试将服务调用封装在 try/catch 块中时,应用程序就挂在那里。这是代码:

服务器端:

 class TransferService: ITransferService
    {
        public FileStream DownloadFile(string filename)
        {
            //string FilePath = Path.Combine(@"c:\Uploads", filename);

            FileStream result = File.Open(@"C:\Uploads\test.wmv", FileMode.Open, FileAccess.Read, FileShare.Read);
            return result;
        }

        public void UploadFile(FileStream request)
        {
            //Not yet implemented
        }
    }

服务器端(web.config):

    <configuration>

    <system.web>
        <compilation debug="true" targetFramework="4.0" />
        <httpRuntime maxRequestLength="100240" />
    </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="basicHttp" allowCookies="true"
                 maxReceivedMessageSize="20000000"
                 maxBufferSize="20000000"
                 maxBufferPoolSize="20000000" transferMode="Buffered">
          <readerQuotas maxDepth="200000000"
                        maxArrayLength="200000000"
                        maxStringContentLength="200000000"
                        maxBytesPerRead="200000000"
                        maxNameTableCharCount="200000000"/>
        </binding>
      </basicHttpBinding>
    </bindings>

    <services>
      <service name="VideoService.TransferService" behaviorConfiguration="VideoServiceTypeBehaviors" >
        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
        <endpoint contract="VideoService.ITransferService" binding="basicHttpBinding" address="basic" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/"/>
          </baseAddresses>
        </host>
      </service>
    </services>

        <behaviors>
          <serviceBehaviors>
            <behavior name="VideoServiceTypeBehaviors" >
              <serviceMetadata httpGetEnabled="true" />
            </behavior>
          </serviceBehaviors>
        </behaviors>

  </system.serviceModel>
</configuration>

客户端:

    public partial class Page1 : PhoneApplicationPage
        {
            TransferServiceClient sc;
            public Page1()
            {
                InitializeComponent();
                sc = new TransferServiceClient();
                this.Loaded += new RoutedEventHandler(Page_Loaded);
            }
            void Page_Loaded(object sender, RoutedEventArgs e)
            {

                sc.DownloadFileCompleted += new EventHandler<DownloadFileCompletedEventArgs>(sc_DownloadFileCompleted); //I think the problem is here
                sc.DownloadFileAsync("test.wmv");
            }
void sc_DownloadFileCompleted(object sender, DownloadFileCompletedEventArgs e)
        {
            myMediaElement.SetSource(e.Result);
            myMediaElement.Play();
        }

客户端(ServiceReference.clientconfig):

<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_ITransferService" closeTimeout="00:02:00"
          openTimeout="00:02:00" receiveTimeout="00:10:00" sendTimeout="00:02:00"
          maxBufferSize="210005536" maxReceivedMessageSize="210005536"
          textEncoding="utf-8">
          <security mode="None" />
        </binding>
        <binding name="BasicHttpBinding_ITransferService1" maxBufferSize="2147483647"
          maxReceivedMessageSize="2147483647">
          <security mode="None" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:53163/TransferService.svc/basic"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITransferService1"
        contract="TransferService.ITransferService" name="BasicHttpBinding_ITransferService" />
    </client>
  </system.serviceModel>
</configuration>

任何帮助或见解将不胜感激。谢谢

4

1 回答 1

0

first i would try to use this code block correctly:

sc.DownloadFileCompleted += new EventHandler(sc_DownloadFileCompleted); //I think the problem is here sc.DownloadFileAsync("test.wmv"); myMediaElement.Play();

you fire up an asynchronous download-process and you are attaching a "download complete"-callback to it... why do you call "myMediaElement.Play" synchronously AFTER the asynchronous invoke? at this time, the file isn't downloaded yet and maybe the mediaelement fires the exception, because the file is locked (because of the download).

you have to call "myMediaElement" in the "sc_DownloadFileCompleted"-Handler AFTER the asynchronous download process finished....

please check if this was the prob...

于 2012-08-13T23:41:12.350 回答