Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3843352
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:55:32+00:00 2026-05-19T15:55:32+00:00

In my web project I have a TestStreamingService.svc file containing a REST service. The

  • 0

In my web project I have a TestStreamingService.svc file containing a REST service.

The service contract :

[ServiceContract(Namespace = "")]
    public interface ITestStreamingService
    {
        [OperationContract]
        [WebGet(UriTemplate = "Download?file={file}&size={size}")] //file irrelevant, size = returned size of the download
        Stream Download(string file, long size);

        [OperationContract]
        [WebInvoke(UriTemplate= "Upload?file={file}&size={size}", Method = "POST")]
        void Upload(string file, long size, Stream fileContent);

        [OperationContract(AsyncPattern=true)]
        [WebInvoke(UriTemplate = "BeginAsyncUpload?file={file}", Method = "POST")]
        IAsyncResult BeginAsyncUpload(string file, Stream data, AsyncCallback callback, object asyncState);

        void EndAsyncUpload(IAsyncResult ar);

    } 

The service implementation (the *.svc file)

using System;
using System.IO;
using System.ServiceModel;
using System.ServiceModel.Activation;
using ICode.SHF.Tests;

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
public class TestStreamingService : ITestStreamingService
{

public Stream Download(string file, long size)
{
    return new SHFTestStream(size);
}

public void Upload(string file, long size, Stream fileContent)
{            
    FileInfo f = new FileInfo(String.Format(@"C:\{0}", file));

    using (FileStream fs = f.Create())
    {
        CopyStream(fileContent, fs);
        fs.Flush();
        fs.Close();
    }
}

public IAsyncResult BeginAsyncUpload(string file, Stream data, AsyncCallback callback, object asyncState)
{
    return new CompletedAsyncResult<Stream>(data, file);
}

public void EndAsyncUpload(IAsyncResult ar)
{
    Stream data = ((CompletedAsyncResult<Stream>)ar).Data;
    string file = ((CompletedAsyncResult<Stream>)ar).File;
    StreamToFile(data, file);
}

private void StreamToFile(Stream data, string file)
{
    string subDir = Guid.NewGuid().ToString("N");
    string uploadDir = Path.Combine(Path.GetDirectoryName(typeof(TestStreamingService).Assembly.Location), subDir);
    Directory.CreateDirectory(uploadDir);

    byte[] buff = new byte[0x10000];

    using (FileStream fs = new FileStream(Path.Combine(uploadDir, file), FileMode.Create))
    {
        int bytesRead = data.Read(buff, 0, buff.Length);
        while (bytesRead > 0)
        {
            fs.Write(buff, 0, bytesRead);
            bytesRead = data.Read(buff, 0, buff.Length);
        }
    }
}

}

public class CompletedAsyncResult : IAsyncResult
{
T data;

string file;

public CompletedAsyncResult(T data, string file)
{ this.data = data; this.file = file; }

public T Data
{ get { return data; } }

public string File
{ get { return file; } }

#region IAsyncResult Members

public object AsyncState
{
    get { return (object)data; }
}

public System.Threading.WaitHandle AsyncWaitHandle
{
    get { throw new NotImplementedException(); }
}

public bool CompletedSynchronously
{
    get { return true; }
}

public bool IsCompleted
{
    get { return true; }
}

#endregion

}

My Web.Config

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>

    <system.serviceModel>
        <behaviors>          
            <serviceBehaviors>
                <behavior name="">                  
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="true"/>
                </behavior>              
            </serviceBehaviors>
          <endpointBehaviors>
            <behavior name="REST">
              <webHttp/>             
            </behavior>
          </endpointBehaviors>
        </behaviors>
        <bindings>
            <webHttpBinding>
                <binding name="ICode.SHF.SL.Tests.Web.TestStreamingService.customBinding0"/>                                                        
            </webHttpBinding>
        </bindings>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
            />
        <services>          
            <service name="ICode.SHF.SL.Tests.Web.TestStreamingService">
              <host>
                <baseAddresses>
                  <add baseAddress="http://localhost:40000/Streaming"/>
                </baseAddresses>
              </host>
                <endpoint name="TestStreamingEndpoint" address="RESTService" binding="webHttpBinding" bindingConfiguration="ICode.SHF.SL.Tests.Web.TestStreamingService.customBinding0"
                    contract="ICode.SHF.SL.Tests.Web.ITestStreamingService" behaviorConfiguration="REST"/>

                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />                
            </service>
        </services>
    </system.serviceModel>  
</configuration>

I’m trying to consume the service from silverlight (the web project contains a clientaccesspolicy.xml) via a WebClient however I seem to fail, Fiddler doesn’t show any calls being made.

(using WebClient.OpenWriteAsync (for upload) & OpenReadAsync (for download))

The uri used for the Client is : “http://localhost:40000/Streaming/Service/Download?file=xxx&size=65536&#8221;

When I use the following uri in IE : “http://localhost:40000/TestStreamingService.svc/Download?file=xxx&size=65536&#8221; a download operation begins and the downloaded file matches the size passed.

I’m not having success with the IE uri in the WebClient though.

Could anyone please explain to me what am I doing wrong? It seems I’ve missed something fundamental…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T15:55:33+00:00Added an answer on May 19, 2026 at 3:55 pm

    It would appear that I’ve managed to solve my problem regarding the Downloading capability from Silverlight via. WebClient.

    Here’s what I did.

    1. Moved the service contract and implementation to a separate project MyWCFLibrary (WCF Service Library)
    2. Added a reference of the said library to the ASP.NET website hosting the project
    3. Added a text file “Service.svc” and edited it :

      <%@ ServiceHost Language=”C#” Debug=”true” Service=”MyWCFLibrary.TestStreamingService” Factory=”System.ServiceModel.Activation.WebServiceHostFactory” %>

    4. Modified the WebClient operation’s uri to match the *.svc file

    Seems that it worked.

    I’m still attemptring to figure one thing out, so comments are welcome :

    I can perform an operation on the service via the Webclient like this :

    WebClient wc = new WebClient();
     string uri = String.Format("http://localhost.:40000/Service.svc/Download?file=xxx&size={0}", size);
                    wc.OpenReadAsync(new Uri(uri));
    

    but not like this :

     string uri = String.Format("http://localhost.:40000/Services/StreamingService/Download?file=xxx&size={0}", size);
                    wc.OpenReadAsync(new Uri(uri));
    

    Where : localhost:40000/Services is the base address of the service and StreamingService is the address of the endpoint (latest changes in my WebConfig)

    Can anyone explain why? or am I stuck with using the 1st uri by default?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my mvc3 web project I have an App_GlobalResources folder containing the resource file
I have developed a web project. Which is generating log file using log4j. But
I have one web application with two projects: Project Website Using CMS; namespace Web
If you create an ASP.NET web file project you have direct access to the
In dynamic Web Project I have - default.html page <!DOCTYPE html PUBLIC -//W3C//DTD HTML
I have web project with file like this: <%@ Page Language=C# AutoEventWireup=true CodeBehind=XXX Inherits=XXX
In the File System Editor under the Web Setup project I have witch says
This is for a web project so i have several classes that inherit from
In my ASP.NET Web-form Project I have an Event which Export Data ( List<Profit>
Hello Ruby/Rails/Merb developers! Im currently working on a web project that will have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.