Tipps Webspace Details Tools Windows Mobile Fun Development SQL Official Sites Virtualization Slide Decks Napster Storage BizTalk Media Center Tablet PC Shopping Diverse Searching Wii Templates Live Writer Silverlight Sidebar Gadgets SOA RFID SharePoint MindMapping Oslo Dublin Windows Azure TV WCF Twitter
André Dammeyer
Dipl. Informatiker, Developer & Software Architect

homeBlogOfADamdownloadssocial webresumecontact

BlogOfADam (rss)

Contains various stuff from André Dammeyer.


HowTo: Dynamic Loading of XAML through WCF-Service, Donnerstag, 3. Juni 2010 23:03:21

Download VS2010-Solution.

  • Create a WCF-service with one method
    • String SubmitAndGetXaml(string commandParameter)
      • The method loads a Xaml file with the name that is specified by commandParameter from disk
  • Create a WPF-Application with a main window
    • The main window contains a ContentControl-control
  • Add a reference to the WCF-service
  • In the constructor call the SubmitAndGetXaml with a parameter that points to a Xaml-file in the WCF-service
  • Use XamlReader.Parse to parse the return value of the SubmitAndGetXaml-method
  • Assign the result of the XamlReader.Parse-method to the content-property of the ContentControl of the main window

To allow interaction within your dynamic loaded Xamls,…

  • Implement a generic button-handler with in the code-behind of the main window
  • Add "ButtonBase.Click='button_OnSubmit'" (where "button_OnSubmit" is the name of the generic button-handler) to the main window grid
  • Test if current button name is "Submit"
    • If the condition is true, call the SubmitAndGetXaml and use as parameter the CommandParameter-property of the button-object

Note: This has to be done for each type of control that needs some code-behind action.

feedback


Interestin Stuff about Large Message Transfer with WCF-Adapters from Paolo Salvatori, Samstag, 29. Mai 2010 22:00:26

a good summary of howto deal with large messages in general and especially with WCF…

feedback


How to integrate on-premise BizTalk apps with Azure (here Service Bus)?, Samstag, 18. Juli 2009 15:03:50

Nice walk-through from Richard Seroter: Securely Calling Azure Service Bus From BizTalk Server 2009 « Richard Seroter’s Architecture Musings

feedback


Screencast: Streamed Messages in WCF, Sonntag, 12. Juli 2009 22:59:25

feedback


Webcast: Working with large messages in WCF (1 of 2) from Richard Blewett, Sonntag, 21. Juni 2009 23:12:28

feedback


BizTalk WCF Adapter Videos, Dienstag, 16. Juni 2009 22:13:43

feedback


Hosting Azure Web Roles Under .NET Full Trust, Freitag, 5. Juni 2009 13:39:52

feedback


Very good WCF Tips & Tricks Slides from Christian Weyer, Mittwoch, 25. März 2009 18:31:21

feedback


Video: How a WCF Receive Adapter Processes an Incoming WCF Message, Mittwoch, 18. März 2009 21:15:17

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.

feedback


WCF Adapter FAQs, Mittwoch, 11. März 2009 22:08:33

Download details: WCF Adapter FAQs

feedback


A Custom WCF Lob Adapter Walk Through from Michael Stephenson, Dienstag, 10. Februar 2009 08:20:18

look at My First Custom WCF Lob Adapter Walk Through

feedback


Slides: Microsoft integration with BizTalk, WCF, WF, Mittwoch, 28. Januar 2009 10:14:07

ACSUG - Auckland Connected Systems User Group - Microsoft integration with BizTalk, WCF, WF

from Kevin Gock and Thiago Almeida.

feedback


Large Message transfer through WCF in Windows Azure, Dienstag, 23. Dezember 2008 21:54:30

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:

  1. Windows Azure gives only partial trust to its applications.
  2. WCF does not support any feature in partial trust.
    1. i.e. it is not possible to configure a binding configuration for the BasicHttpBinding that changes the transferMode and maxReceivedMessageSize to enable streaming.
  3. Streaming through WCF seems not to work within cassini (see also InfoWorker Solutions: WCF Streaming: Upload files over HTTP).

 

My solutions (or better workarounds)

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;
    }        
}

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>

feedback


WCF Partial Trust Restrictions, Dienstag, 23. Dezember 2008 11:10:36

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:

feedback


WCF and the Cloud, Montag, 22. Dezember 2008 17:02:46

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.

feedback


Streaming WCF Sample, Montag, 22. Dezember 2008 14:47:44

Download WCFStreamSolution.zip .

Motivation

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.

Preperations

All steps will only be described for C#.

  1. Open Visual Studio 2008 and create a Blank Solution and name it WCFStreamSolution.

Service

  1. Right click on WCFStreamSolution, Add a New Project, select Windows Console Application and name it WCFStreamService.
  2. Add a Reference to System.ServiceModel.

Interface

  1. Define the contract as an interface. For that purpose right click on WCFStreamService and Add New Item Interface. Name the Interface IStreamService.cs.
    1. insert using System.ServiceModel; and using System.IO; into IStreamService.cs.
    2. Make the interface IStreamService public.
    3. Add [ServiceContract(Namespace = http://StreamService)] above the interface IStreamService.
    4. Add two methods with the attribute [OperationContract]. void Upload(Stream dataStream); and Stream Download(string id);

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);
    }
}

Service Implementation

  1. Implement the interface. For that purpose right click on WCFStreamService and Add New itrem Class. Name the class StreamService.cs.
    1. For the sample implementation see below!

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
    }
}

Service Host and Configuration

  1. Implement a host for the WCF service. For that purpose open the Program.cs.
    1. insert using System.ServiceModel; and using System.ServiceModel.Description; into Program.cs.
    2. Create a URI, i.e. Uri baseAddress = new Uri("http://localhost:8000/StreamService");
    3. Create a ServiceHost that uses the definied URI, i.e. ServiceHost selfHost = new ServiceHost(typeof(StreamService), baseAddress);
    4. Create a Custom Binding.
      1. Important: Set the TransferMode to TransferMode.Streamed. This means that the service offers operations that need parameters to be streamed in both directions, from sender to receiver and back.
      2. Important: Set the MaxReceivedMessageSize to a higher limit (default is 65536 Bytes), i.e. 10485760.
    5. Set the metadata behavior of HttpGetEnabled to true.
    6. Add an Endpoint to the ServiceHost, i.e. selfHost.AddServiceEndpoint(typeof(IStreamService), binding, "StreamService");.
    7. Open the ServiceHost and wait for requests.
    8. Last but not least Close the ServiceHost before leaving the console application.

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());
            }
 
        }
    }
}

To do a first test of the web service open your browser and enter the specified URI (in the sample http://localhost:8000/StreamService).

Client

  1. Right click on WCFStreamSolution, Add a New Project, select Windows Console Application and name it WCFStreamClient.
  2. Add a Reference to System.ServiceModel.

Generate Proxy and App.Config

  1. Right click on WCFStreamClient and Add New Item Textfile. Name the Textfile generate.cmd.
    1. insert the following lines into generate.cmd:
      call "c:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86
      svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config http://localhost:8000/StreamService
    2. Important: Save generate.cmd as ANSI encoded, not UTF-8!
    3. Important: Start the WCFStreamService.
    4. Execute generate.cmd.
    5. Right click on WCFStreamClient and Add Existing Item. Select the App.Config and GeneratedProxy.cs.

Client Code

  1. Open Program.cs.
    1. Instantiate the generated proxy class (here: StreamServiceClient).
    2. Open a file stream and call the Upload-method of the proxy.
    3. Call the Download-method of the proxy.

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());
            }
 
        }
    }
}

feedback


WCF Screencasts, Donnerstag, 18. Dezember 2008 22:31:57

All WCF Screencasts (RSS for all posts in the series)

feedback


WCF Virtual Labs, Donnerstag, 18. Dezember 2008 22:24:29

Nicholas Allen's Indigo Blog : WCF Virtual Labs

feedback


Copyright © 2009 by André Dammeyer.