homeBlogOfADamdownloadssocial webresumecontact
Contains various stuff from André Dammeyer.
Download VS2010-Solution.
To allow interaction within your dynamic loaded Xamls,…
Note: This has to be done for each type of control that needs some code-behind action.
feedback
a good summary of howto deal with large messages in general and especially with WCF…
Nice walk-through from Richard Seroter: Securely Calling Azure Service Bus From BizTalk Server 2009 « Richard Seroter’s Architecture Musings
This Windows Communication Foundation (WCF) video examines the flow of an incoming WCF message into a BizTalk receive location that is configured to use a WCF receive adapter.
Download details: WCF Adapter FAQs
look at My First Custom WCF Lob Adapter Walk Through
ACSUG - Auckland Connected Systems User Group - Microsoft integration with BizTalk, WCF, WF
from Kevin Gock and Thiago Almeida.
I had heavy problems to implement my streaming WCF service that will be hosted in Windows Azure. I had to deal with the following issues and/or its consequences:
I created my own ServiceHostFactory to change the BasicHttpBinding configuration programmatically (see also Pimp Your WCF Runtime - Episode One).
MyServiceHostFactory.cs:
public class MyServiceHostFactory : ServiceHostFactory { protected override System.ServiceModel.ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses) { ServiceHost host = base.CreateServiceHost(serviceType, baseAddresses); BasicHttpBinding binding = (BasicHttpBinding) host.Description.Endpoints[0].Binding; binding.TransferMode = TransferMode.Streamed; int limit = 1024*1024*100; binding.MaxReceivedMessageSize = limit; binding.MaxBufferSize = limit; binding.MaxBufferPoolSize = limit; //RoleManager.WriteToLog("Information", "ServiceHost created!"); return host; } }
public class MyServiceHostFactory : ServiceHostFactory
{
protected override System.ServiceModel.ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
ServiceHost host = base.CreateServiceHost(serviceType, baseAddresses);
BasicHttpBinding binding = (BasicHttpBinding) host.Description.Endpoints[0].Binding;
binding.TransferMode = TransferMode.Streamed;
int limit = 1024*1024*100;
binding.MaxReceivedMessageSize = limit;
binding.MaxBufferSize = limit;
binding.MaxBufferPoolSize = limit;
//RoleManager.WriteToLog("Information", "ServiceHost created!");
return host;
}
MyService.svc:
<%@ ServiceHost Language="C#" Debug="true" Service="MyWcfCloudService_WebRole.MyService" CodeBehind="MyService.svc.cs" Factory="MyWcfCloudService_WebRole.MyServiceHostFactory" %>
Set the max to a higher value, in my example 32768 Bytes (see also httpRuntime Element (ASP.NET Settings Schema)).
Web.Config:
<system.web> <httpRuntime maxRequestLength="32768"/> </system.web>
<system.web>
<httpRuntime maxRequestLength="32768"/>
</system.web>
If I am right, in the Windows Azure CTP the applications and services in the cloud run under partial trust. This has some consequences. In my use case I have to implement a WCF service that supports streaming. For that purpose I have to override the MaxReceivedMessageSize and TransferMode (see also BlogOfADam – Streaming WCF Sample) settings of the basicHttpBinding. This seems to be possible only with full trust.
Some links of interest about trust settings:
I just made a Web Cloud Service and added a simple WCF service to it. When I tried to consume the simple WCF service I ran into a problem. Due to an issue with the WSDL page within the development fabric, it seems to be not possible to generate the client proxy class for consuming the WCF service. Therefore I had to create the proxy class and the App.Config by right clicking on my simple WCF service and select View in Browser. Then I used the URL from the browser to generate the proxy class and the App.Config. To use the proxy class and the App.Config to access the simple WCF service in my Web Cloud Service I had to change the endpoint address within the App.Config.
UPDATE: see also WCF Service in Web Role : Windows Azure : Azure : MSDN Forums.
Download WCFStreamSolution.zip .
Because I have to write a WCF facade to a Windows Azure / SDS storage solution that has to deal with large data, I had to learn something about streaming in Windows Communication Foundation. Therefore I wrote this walkthrough.
All steps will only be described for C#.
IStreamService.cs:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ServiceModel; using System.IO; namespace WCFStreamService { [ServiceContract(Namespace = "http://StreamService")] public interface IStreamService { [OperationContract] void Upload(Stream dataStream); [OperationContract] Stream Download(long size); } }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.IO;
namespace WCFStreamService
[ServiceContract(Namespace = "http://StreamService")]
public interface IStreamService
[OperationContract]
void Upload(Stream dataStream);
Stream Download(long size);
StreamService.cs:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace WCFStreamService { class StreamService : IStreamService { #region IStreamService Members public void Upload(Stream dataStream) { Console.WriteLine("Service: Begin Upload"); try { // Consume the stream! using (StreamReader reader = new StreamReader(dataStream)) { while (!reader.EndOfStream) reader.Read(); } } finally { Console.WriteLine("Service: End Upload"); } } public Stream Download(long size) { MemoryStream dataStream = new MemoryStream(); StreamWriter writer = new StreamWriter(dataStream); for (long i = 0; i < size; i++) { writer.Write('A'); } writer.Flush(); dataStream.Seek(0, SeekOrigin.Begin); return dataStream; } #endregion } }
class StreamService : IStreamService
#region IStreamService Members
public void Upload(Stream dataStream)
Console.WriteLine("Service: Begin Upload");
try
// Consume the stream!
using (StreamReader reader = new StreamReader(dataStream))
while (!reader.EndOfStream)
reader.Read();
finally
Console.WriteLine("Service: End Upload");
public Stream Download(long size)
MemoryStream dataStream = new MemoryStream();
StreamWriter writer = new StreamWriter(dataStream);
for (long i = 0; i < size; i++)
writer.Write('A');
writer.Flush();
dataStream.Seek(0, SeekOrigin.Begin);
return dataStream;
#endregion
Program.cs (Service):
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ServiceModel; using System.ServiceModel.Description; namespace WCFStreamService { class Program { static void Main(string[] args) { ServiceHost selfHost = null; try { Uri baseAddress = new Uri("http://localhost:8000/StreamService"); selfHost = new ServiceHost(typeof(StreamService), baseAddress); BasicHttpBinding binding = new BasicHttpBinding(); binding.TransferMode = TransferMode.Streamed; binding.MaxReceivedMessageSize = 10485760; ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; selfHost.Description.Behaviors.Add(smb); selfHost.AddServiceEndpoint(typeof(IStreamService), binding, "StreamService"); selfHost.Open(); Console.WriteLine("The service is ready."); Console.WriteLine("Press <ENTER> to terminate service."); Console.WriteLine(); Console.ReadLine(); // Close the ServiceHostBase to shutdown the service. selfHost.Close(); } catch (Exception ex) { if (selfHost != null) selfHost.Abort(); Console.WriteLine(ex.ToString()); } } } }
using System.ServiceModel.Description;
class Program
static void Main(string[] args)
ServiceHost selfHost = null;
Uri baseAddress = new Uri("http://localhost:8000/StreamService");
selfHost = new ServiceHost(typeof(StreamService), baseAddress);
BasicHttpBinding binding = new BasicHttpBinding();
binding.MaxReceivedMessageSize = 10485760;
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
selfHost.Description.Behaviors.Add(smb);
selfHost.AddServiceEndpoint(typeof(IStreamService), binding, "StreamService");
selfHost.Open();
Console.WriteLine("The service is ready.");
Console.WriteLine("Press <ENTER> to terminate service.");
Console.WriteLine();
Console.ReadLine();
// Close the ServiceHostBase to shutdown the service.
selfHost.Close();
catch (Exception ex)
if (selfHost != null)
selfHost.Abort();
Console.WriteLine(ex.ToString());
To do a first test of the web service open your browser and enter the specified URI (in the sample http://localhost:8000/StreamService).
Program.cs (Client):
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ServiceModel; using System.IO; namespace WCFStreamClient { class Program { static void Main(string[] args) { StreamServiceClient client = new StreamServiceClient(); string streamName = @"..\..\blob.pdf"; Console.WriteLine("Client: Start upload {0}", streamName); Stream stream = File.OpenRead(streamName); client.Upload(stream); Console.WriteLine("Client: Finished upload {0}", streamName); Stream outStream = client.Download(100); using (StreamReader reader = new StreamReader(outStream)) { Console.WriteLine("Client: Download returned '{0}'", reader.ReadToEnd()); } } } }
namespace WCFStreamClient
StreamServiceClient client = new StreamServiceClient();
string streamName = @"..\..\blob.pdf";
Console.WriteLine("Client: Start upload {0}", streamName);
Stream stream = File.OpenRead(streamName);
client.Upload(stream);
Console.WriteLine("Client: Finished upload {0}", streamName);
Stream outStream = client.Download(100);
using (StreamReader reader = new StreamReader(outStream))
Console.WriteLine("Client: Download returned '{0}'", reader.ReadToEnd());
All WCF Screencasts (RSS for all posts in the series)
Nicholas Allen's Indigo Blog : WCF Virtual Labs
Copyright © 2009 by André Dammeyer.