Sep
10
2008

WCF Add Service Reference issue with Visual Studio 2008 SP1

The other day I faced a strange issue when I wanted to add a service reference to the Tech Head Brothers authoring tool. The code generated wasn’t compiling with errors located in the file Reference.cs.

Drilling down the issue I figured out that the default namespace, TechHeadBrothers.Word, was the issue. It was just added at some place and at other not.

I made then a quick test with another assembly which had no dot in it’s name. That’s was it! The issue was the dot into the Assembly name, Default namespace.

Don’t use . in the name of your Assembly name, Default namespace to get back to normal state, weird!

Sep
7
2008

Video of Tech Head Brothers new authoring tool based on Word 2007

In the following video I present the different features of the new authoring tool for my portal Tech Head Brothers.

First you will see the use of ClickOnce to enable easy installation on the author computer. This will also allow an easy update scenario. A great plus compared to the past.

Then you will see the Word 2007 template using to author the content of an article. It shows:

  1. Definition of the Title
  2. Definition of the Description
  3. Definition of the Keywords
  4. Writing of the content of a section of content with bold, italic, list, hyperlink
  5. Adding some sample code directly copied from Visual Studio 2008
  6. Inserting sample code in a zip
  7. Adding a picture captured using SnagIt yo the article
  8. Offline preview in Internet Explorer
  9. Posting to the Tech Head Brothers web site with Tags selection
  10. Online preview of the posted content

Enjoy the video! (Without sound, I couldn’t find a micro at home :()

Sep
6
2008

New step in my authoring tool using Word 2007

This evening I took the time to implement a new step on the new version of Tech Head Brothers authoring tool.

Now I am able to write an article in Word 2007 and post it using Web Services.

The next picture is the result of posting from Word 2007 on the web site using Web Services:

Here is how it looks like in Word:

To insert some source code sample as you can see on the Word 2007 picture or the web site, it is really easy. Go in Visual Studio, copy the code you want in the clipboard. Switch to Word 2007, then use the Source Code button:

To insert a picture, either use Windows Explorer to copy a file into the clipboard and paste it into the Word 2007 document, or use a tool like SnagIt from TechSmith (Thanks for the license by the way!!), make a screen shot, copy result into the clipboard and paste into Word 2007.

Is that easy!

This tool will make the authoring process on Tech Head Brothers so easy.

Aug
9
2008

Tech Head Brothers new authoring tool, step 8

For three night now I focused on one scenario for the Tech Head Brothers authoring tool:

  • As an author I want to be able to copy source code from Visual Studio and insert it into the authored Word document
  • As an author I want to preview a document with source code inserted in Internet Explorer

This might not look really difficult at first, but I had some difficulties to fulfill the requirements of those two user story.

The first one was almost already implemented in step 7, using CustomXML capabilities of WordML.

The biggest issue I had was to figure out why when I was inserting CustomXML, the WordML format of the hyperlink was changing. It took me the most time to realize that inserting CustomXML was not the issue. The issue was proofing. Somehow inserting CustomXML was activating the auto proofing and then I got some error like on the following picture. The red underlined Brothers which is a link was the issue. In fact this simple thing change the WordML representation of the hyperlink.

As I had something working I had to find a way other than adding a second way to parse Hyperlinks. I came to the solution of disabling proofing then saving the document before making my projection to Tech Head Brothers XML. Then for sure re-enabling the proofing. Nice and easy!

The next issue was to be able at the time of parsing the WordML to identify that source code was at at the current position in the WordML. I turned and turned the problem, than asked some clever WordML guys (Julien, Pierre) and some generally good advisor (Mitsu, Cyril). Nothing! I finally came to a solution tonight:

  1. Getting the Id of the PlainTextContentControl from the WordML
  2. Searching for this Control in the Controls collection
  3. Finally using the plainTextContentControl.XMLMapping.CustomXMLPart.XML property I had access to my CustomXML

I couldn’t find any way to do that parsing the WordML and honestly tonight I don’t know how it is possible to go from the WordML to the CustomXML.

The result is here!

Copying source code from Visual Studio

Inserting it in Word 2007

Final result in Internet Explorer

 

There is still a little bug with the spacing that will solved tomorrow or later!

Now the next steps will be:

  1. Projection of hyperlink
  2. Projection of picture
  3. Projection of numbered list and bullet list
  4. Fixing bugs found by Sébastien and Rédo
  5. Picture caption
  6. Giving the possibility to insert source code
  7. Projection of the source code
  8. Adding the possibility to the author to post the article directly from Word to Tech Head Brothers web site using secured web services made out of WCF
  9. Adding all validation of the content
Mar
12
2008

Tech Head Brothers new authoring tool, step 7

I finally got time to go on with the new Tech Head Brothers publishing tool!

This time I wanted to go on with source code and I reached a quite good status.

The usage scenario is as following:

  1. In Visual Studio the author select source code that he wants to publish on his article
  2. The author switch to Word 2007 an click on Source Code button and the code is automatically inserted

As you can see on the following pictures!

Behind the scene:

  1. I get the code from the clipboard,
  2. Build up a XML document with one tag representing the source code in html and inline css and another of pure text
  3. Insert a CustomXML part into the Word 2007 document
  4. Insert a PlainTextContentControl into the document with read only rights
  5. Uses XML mapping to display the text tag into the PlainTextContentControl

Great! I look forward to see the projection of the source code to HTML and preview it into the browser!

So the next steps will be:

  1. Projection of hyperlink
  2. Projection of picture
  3. Projection of numbered list and bullet list
  4. Fixing bugs found by Sébastien and Rédo
  5. Picture caption
  6. Giving the possibility to insert source code
  7. Projection of the source code
  8. Adding the possibility to the author to post the article directly from Word to Tech Head Brothers web site using secured web services made out of WCF
  9. Adding all validation of the content
Aug
31
2007

Video of Tech Head Brothers authoring tool using Silverlight Streaming

This is a video demonstrating the offline usage of the Tech Head Brothers authoring tool.

The tool is using now WCF in place of WSE3 and works great with ASP.NET membership and role.

The video is hosted on Silverlight Streaming and was made using Camtasia Studio from TechSmith and Microsoft Media Encoder.

Aug
31
2007

Tech Head Brothers Authoring tool

I just updated the source code of my Tech Head Brothers Authoring tool on Codeplex.

Now it uses Windows Communication Foundation (WCF) in place of WSE 3.0 and Word 2007.

Tech Head Brothers Authoring Tool is a content authoring tool based on Word 2007, VSTO 2005se, XML, XSLT and Web Services (WCF).
It permits offline content authoring and pre-visualization then online publishing to the French portal Tech Head Brothers - http://www.techheadbrothers.com.
Currently the tool let the author:

  • Choose images to insert using a Document Action Pane
  • Copy source code from Visual Studio and paste it into Word 2007, generating an external source code colorized XHTML file using Colin Coller CopySourceAsHtml http://www.jtleigh.com/people/colin/software/CopySourceAsHtml/
  • Have a local disconnected preview of there publication rendering through a XSLT rendering
  • Post there content on the website using Web Services
Aug
2
2007
WCF

Issue with WCF Services hosted in IIS using multiple bindings per site

I am currently working on the new Tech Head Brothers authoring tool THBAuthoring as you can read in this post 'Migration from WSE 3 to WCF'. Two days ago I went to production with the migration from WSE to WCF. Today I had to post an article about Linq written by Kader Yildirim and was quite optimistic that it will work because I followed as always the process of developing on my notebook, then deploying to staging, testing of staging and finally going to production. This time it didn't work. I had a the following error:

"This collection already contains an address with scheme http. there can be at most one address per scheme in this collection."

Weird

I did a comparison using WinMerge of the web.config of staging and production web site, and nothing special in there.

After some research on the configuration of the web site in IIS I realized that the production one was using multiple bindings and the one from staging was not. Removing all bindings except the one defined in the WCF service made it, now my service is working.

Even if it is not a really good solution I can leave with it for the moment. And with some research I found this post from Ram Poornalingam 'Supporting Multiple IIS Bindings Per Site' that I have not tried right now but will asap.

Jun
27
2007

Migration from WSE 3 to WCF

I started to migrate the Tech Head Brothers authoring tool and portal from Web Service Enhancement 3 (WSE 3) to Windows Communication Foundation (WCF). This is a next step in the integration of .NET Framework 3 in Tech Head Brothers portal.

Till today I was using WSE 3 from the Word VSTO solution to securely publish content to the portal directly out of Word 2003/2007.

The migration went straight due to my initial implementation that was already using interfaces and implementation classes. So basically I had to :

  • Remove the reference to WSE 3 and add one to System.ServiceModel
  • Change the attributes on the interface to ServiceContract and OperationContract
  • Update the web.config to parameterize the new WCF endpoint, binding...
  • Regenerate the client proxy and update a bit the client code

This first step took me around 1h30 and was working very good but was still missing all the security of the old version.

Then to implement the security part of the web services:

  • I created a new certificate
  • Removed the Policy using the self developed aspnetUsernameTokenSecurity that is not needed anymore
  • Configured the web.config with a new wcf service behavior using userNameAuthentication and serviceAuthorization linked to ASP.NET providers
  • Replaced code checking the role of the user calling the service with an attribute PrincipalPermission
  • Regenerated the client proxy and reconfigured it

So now I have security at the level of the message that is encrypted using the certificate and at the web service with role access check.

Currently the solution uses attributes to check the role of the user that access the web service. I don't find the solution flexible enough and the next step will be to have the configuration in a configuration file, that would let me change access rights without changing any line of code.

As always when this will work I will publish the source code of the VSTO client authoring tool (Tech Head Brothers Authoring) on the codeplex project: THBAuthoring.

Jun
22
2007

Legacy code integration using Windows Communication Foundation (WCF) and Java Axis in a Service Oriented Architecture

What are the options when you need to integrate Windows legacy code in a heterogeneous Service Oriented Architecture (SOA)?

The proposed problem was to expose a set of Windows C++ DLLs to a global SOA platform written in Java. Those DLLs would be then exposed as backend computation services.

One of the options used in some past projects was to use the Microsoft SOAP Toolkit. But your C++ DLLs needs to be COM Objects for that. I experienced it and still have production code running with it. It works quite well even with surprising complex data structures. But as today it is definitely not the way to go.

The service oriented world has evolved rapidly over the last years and using such an old deprecated technology (Microsoft SOAP Toolkit) is not really efficient for a project.

So at last it was time to check .NET in this entire Java world ;-)

The general idea was to define a layered solution. From bottom up I first defined an interoperability layer using .NET Interop to be able to call the C++ DLLs from .NET. Then on top of this first layer I added another layer exposing the whole as a web service.

Now that I had the backend web service working I had to call it from Java. So are all those promises of web service interoperability just working out of the box?

Yes and No. You need to first have a real look at the different frameworks stack you want to use. For example, when you are working with Java Axis you are tied to SOAP 1.1, so you have to take care that the other side can understand this version of the SOAP standard.

So what do I have? First I have a client that must be written in Java using Axis 1.2-1.4 using SOAP 1.1, then a C++ Windows DLL backend that must be exposed in an interoperable way. By luck I was free to choose the technology used on that backend. Both ASP.NET web services (ASMX) and WCF can interoperate with the SOAP 1.1 standard, so I decided to go on with C# and WCF.

The way I approached the problem was to go on iteratively, making a first proof of concept to integrate the C++ layer with the .NET layer, then to integrate this upper layer with WCF and a .NET client to finally finish with a Java client.

Due to the ease of the interface exposed by the web service I didn’t wrote it using data contract design first. In more complex scenarios I would definitely go on with it because it leads to better success with interoperability.

So I finally adopted the following final solution.

Adopted solution

On the backend a Windows Communication Foundation web service written in C# using the .NET Framework 3.0. The web service layer uses .NET interop to make a call to the legacy C++ Dlls.

On the client side; a Java 1.5 proxy/stub class generated using WSDL2Java out of the WSDL exposed by the service.

Hosting

The last question concerning the web service was to define the way I wanted to host it?

Two possibilities in my case: Windows Service and Internet Information Services (IIS).

After making some load test on the web service I realized that it was leaking memory so I finally went to the IIS solution because it provides you all the services for recycling a buggy process. It was also easier because some part of the deployment process for web services hosted in IIS were already implemented and tested.

Faced problems

The first minor thing I went through was to check which versions of WCF and Axis are compatible.

Then the C++ interop was the main work because it is not such an easy task to marshal between the different worlds in a correct way.

And finally the last one was that the legacy C++ Dlls where using ifstream to load configuration ini files, without a possibility to specify the full path of those files. As the web application was running in the Application Pool process (w3wp.exe), loading the ini file was using the base path of w3wp.exe; C:\WINDWS\System32\inetsrv\. That would force me to deploy the ini files in that folder. What an ugly solution. Adding the bin folder of the application to the PATH was not making the trick too. And as we couldn’t change the C++ Dlls I had to find something else.

The solution I came to, thanks to David Wang (yes you also Richard ;-), was to use this little method before calling into the legacy Dlls, changing the current directory:

        /// <summary>
        /// Sets the current directory.
        /// </summary>
        private static void SetCurrentDirectory()
        {
            string binpath = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "bin");
            Directory.SetCurrentDirectory(binpath);
        }

Conclusion

I really like the way WCF is handling the separation between the service description, the implementation and the configuration that will define how you expose the service to the world.

The other thing I still enjoy to see is complex systems using so different technologies talking to each other. Here we had a caller written in Java running on a Linux server calling a web service written in C# calling multiple C++ Dlls running on a Windows server.

I am still amazed about those little things!!!

About Laurent

Laurent Kempé

Laurent Kempé is the editor, founder, and primary contributor of Tech Head Brothers, a French portal about Microsoft .NET technologies.

He is currently employed by Innoveo Solutions since 10/2007 as a Senior Solution Architect, certified Scrum Master and Founding Member.

Founder, owner and Managing Partner of Jobping, which provides a unique and efficient platform for connecting Microsoft skilled job seekers with employers using Microsoft technologies.

Laurent was awarded Most Valuable Professional (MVP) by Microsoft from April 2002 to April 2012.

JetBrains Academy Member
Certified ScrumMaster
My status

Twitter

Flickr

www.flickr.com
This is a Flickr badge showing public photos and videos from Laurent Kempé. Make your own badge here.

Month List

Page List