Feed on
Posts
Comments

ADO.NET Dataservice

Hi,

With the release of Visual Studio 2008 SP1 and the .NET Framework 3.5 SP1, ADO.NET Dataservices is also released. With this technology you are able to expose multiple datasource as dataservices. ADO.NET Dataservice uses REST technolgy which means that every datasource is referenced by a URI. I think ADO.NET Dataservice is a technology which will be used very often in the future especially with the upcoming interrest for Silverlight. The project team already made some “How do I” videos available here! Enjoy

Regards

Hi all,

I have to recall my thoughts about the commnadline tool xsd.exe in the post: XML serialization. When an XSD element contains a minoccurs =”0″ and it’s not a string, there will be a property generated with the name. <element name>+Specified. This property is a boolean field which is used to determine if a field needs to be serialized to XML. The default value is false, so if you don’t set this field you won’t be able to see your data back in your XML.

Regards,

Dennis

HI,

Avanade (Gerben van Loon and David Slot) build a very nice extension for WSSF. This extension makes Entlib integration possible for your service layer without programming a single line of code. Very cool. Check it out on CodePlex.

Regards

Hi all,

I’ve been working with Webservice Software Factory (WSSF) for 2 months now and i am pretty happy with this tool. The WSSF provides you with 3 models:

  • ServiceContract
  • DataContract
  • Host

These 3 models can help you with clicking a webservice together. For a nice introduction about WSSF check the following link:

http://msdn2.microsoft.com/nl-nl/magazine/cc164250(en-us).aspx

In this article my colleagues Gerben van Loon and Gerardo de Geest give you a very good first impression of the possiblities of WSSF.

One major thing that’s missing in WSSF is shared types. When you create multiple service contracts based on the same datamodel which is a pretty normal thing to do. Every service that is using the same classes (datacontracts) in the datamodel generates it own version of the class in the proxy.

So Lets say you have Service A and Service B. Both these services use the datacontract Address. When you generate a proxy in the HostModel there will be 2 proxies generated. Both proxies contain the Address datacontract. When you put these proxies in a project “ServiceAgent”, because you want to centralize every proxy in one project you will receive errors because the dataContract Address is ambiguous. 

I think that there are 2 ways to solve this problem:

  • use namspaces
  • generate one central datacontract

Use namespaces
Using namespaces could solve the problem. You can change the namespace that is standard used when you generate the proxy. This means that you should create a new namespace for every proxy you generate. Well i think that namespace should be used to give a good structure to the framework and should not be abused to fix a problem of double generate datacontracts.

Generate one central datacontract
Creating one datacontract which every service can use is ideal, but how could we fix this? When we look at the Host model of WSSF we only have two options:
- Generate Proxy
- Generate Service

If we want to separate the proxy from the datacontract, then we have to change the process for generating the proxy. This could be done in WSSF but if you want to fix this we have to rebuild the whole factory. You could also stop using the generate proxy option of WSSF and create you own generate proxy process with the command-line tool svcutil. This tool provides us with a lot of options to create different kind of objects. We want to create a datacontract (c# file) and a proxy. To fix this it’s important you should use the implementation project Datacontracts within your WSSF solution. This project becomes available when right-clicking on your solution. click Add and then there are 2 WSSF options:

  • ASMX implementation project
  • WCF implementation project

Datacontract

I have selected the second option. When you richt click in your DataContractDesigner you will see an option Generate Code. When your model is valid it will generate the code in 2 of your implementation projects:

  • <name of your project>.DataContract
  • <name of your project>.FaultContract

Because the datacontracts are generated into my implementation project (separated files) i need to build the projects to generate one dll file. This file is important as input for my datacontract and proxy generation. When the dll is available i can generate a file (in my case c#) which will contain all my datacontracts. See the command below:

  • svcutil.exe /dconly <Location of the Datacontract dll>
  • svcutil.exe /dconly <The generated XSD file> /out:<Output location>/n:<Namespace> /s
/dconly The /dconly switch is used to generate only a datacontract.
/out I use the /out switch because i want to define the location where my c# file will be deployed. My output location is the Client application which is also generated when you create your implementation projects. Because my output location is in my Client application i have directly access to my new generated datacontract.
/namespace I use this to make sure that the datacontract will have an appropriate namespace
/s The /s switch is used to make sure that every datacontract will be decorated with the serializable attribute.

The result of the first statement above will be a xsd file, which will be used as input for the second/final statement.

Proxy

Now that we have generated a datacontract we have to instruct the svcutil tool to generate a proxy without generating the datacontracts it uses. This means we have to give a reference to the datacontracts dll we want to use. The statement below is a statement that you can use to fix this:

svcutil.exe <The address of your webservice>  /r:<a reference to the datacontract dll> /r:<a reference to the faultcontract dll> /namespace:<namespace of your proxy> /out:<Output proxy file> /ct:<CollectionTypes>

/r: Used to make a reference to the datacontract or Fault contract dll. You can define multiple reference in on statement
/namespace I use this to make sure that every generate proxy will be in the same namespace
/ct You have to specify the CollectionType datacontracts you have in your datamodel. if you don’t these will still be generate into your proxy. I my example it could be a datacontract Addresses

When you have generated a datacontract and a proxy separately you will never have problems with ambiguous datacontracts.

Regards,

Dennis

 

XML serialization

Hi,

Last week i spend a few hours to analyse and fix a very strange problem. On the project where i am working on right now we have to serialize some objects to XML before we could send it to WebMQ. The objects that need to be serialized are created with the XSD command-line tool. We received an XSD from our customer and generated a class with this XSD.

XSD.exe /c /l:c# <XSD file>

These XSD’s are sometimes huge files so this will generate enormous classes. Before we send our XML reqeust to WebMQ we validate the XML against the XSD to be sure that WebMQ will accept and process our request. At this point i receive messages that the serialized XML isn’t valid, there are some elements missing. I started the debugger and checked if all the values of my object were set before it will be serialized. Everything looks fine, but the XML doens’t contain the values that it put in my object.

When i took a closer look to the XSD file i saw that every property that i have set in my object and isn’t in the XML file has the attribute minOccurs=”0″ defined. So i removed the minOccurs attribute from the XSD, generated a new class again with the XSD command-line tool and tried it again. This time every property was serialized to XML. I couldn’t  believe this was the solution for my problem. minOccurs=”0″ means the least amount of elements that should be in the XML file. So ‘0′ is acceptable but ‘1′ also. I think the problem is within the XSD command-line tool. The reason this took me so long to fix it, was because first i was looking in the wrong direction. I was searching for ingore and serialazable attributes never thought that the minOccurs in the XSD would be the problem. A colleague mentioned that when the XSD is changed which is my contract to communicate with WebMQ that this could introduce a new problem because my message could be invalid. fortunately this was not a problem i validated my XML against an XSD with the minOccurs attribute and my XML was valid.

Regards,

Dennis

Some time ago I decided to write some posts about what happens within the ASP.NET AJAX framework when you build your own control. There are a lot of posts how to create your own control, but i was very interested what happens inside the framework. In this part i will show you how the framework acts on the properties of your control. When you have created a new control you have to instantiate it on a webpage. In figure1 is shown how you could do that. My control will be created when the application is loaded. The first line is just to kick in the debugger so this is a line you can forget.

Creating a control

figure 1

In this post i will focus on the second parameter {name: ‘Control’}. The second parameter is used to set the properties of your control, in this cause i am only using 1 property called name. I set the name of the control to ‘Control’. In figure 2 you can see my property as a parameter.

Property parameter

figure 2

Before the property can be set on the control, the framework has to create the control first. In figure 3 you can see that once the control is created it will live in the code as the variable component.

property2.jpg

figure 3

Once the control is created I am able to set the properties of the control. In figure 4 you can see that the _setProperties function is called with 2 parameters. The control self and the properties I set when in created the control.

Set properties

figure 4

The setProperties is the function where it all happens. There are some if statements to decided how the properties should be set. In Figure 5 you can see an overview of the _setProperties function

property4.jpg

figure 5

Mainly the code block in figure 5 is divided in 2 blocks. The first is used when you have objects defined for your properties for example {style: {fontWeight: “bold”, borderWidth: “2px”}}}. In this case style will be seen as a object and fontWeight en borderWidth as properties. In this block the code will recursively call it self to finally end up in the second block where the real properties will be set. Below I will show in detail how the properties will be set for a control. In figure 6 you can see that there will be looped through the array of properties and that the variable val will be set with the value op the property name. See figure 7. 

property5.jpg

figure 6

property6.jpg 

figure 7

The variable ‘name’ will always contain the name of the property and the variable ‘val’ will always contain the value you want to set for the property. Now that the property and the value are known the framework will set the value. To do this, your control should contain a function to set (in my case name) the property of the control. the syntax for this is “set_”+ the propertyname. If your property doesn’t have a set prefix the function can’t be found. See figure 8 for the code example.

property7.jpg

figure 8

In figure 8 you can see that there will be a setter variable which will act as the property setter and it takes 2 arguments. Target which will be the control where the property is part of and the val (value) of the property. When you step into this line of code you will reach your own control as you can see in figure 9.

property8.jpg 

figure 9

I hope this makes it clear how the framework will work with your control and how it will set your property. In part III I will describe how you can hook up events to your control and how the framework will fix this for you.

Regards,

 Dennis

In this post i would like to show you how cool it is to use the objects you defined in your Business Layer on the client. But first why do you want to use your objects on the client? Well, wouldn’t it be nice to only retrieve some objects from the server once and manipulate the objects, add new objects and when everything is good then send it back to the server to process everything.  This means less data transfers. With the ASP.NET AJAX framework this is very easy to achieve. I have a webpage which communicates with a webservice to retrieve some information from the server. My webservice only contains two webmethods. A getHouse and a saveHouse Webmethod.

[WebMethod]

public House GetHouse()

{

return new House();

}

In this case I created a Class House which will be send to the client when the webmethod GetHouse is executed. As you can see below the house object in the Business Namespace is available on the client.GetHouse

The reason this object is available on the client is because I have set a reference to the webservice in the Scriptmanager. The Scriptmanager will create a Javascript proxy to enable communication with the  webservice. Because I have defined a webmethod where I use an object House this object will be generated in the Javascript proxy as show in de second screenshot.

 RegisterHouseClass

Here you can see that first the namespace is created and later the House object will be registered in the Business namespace. Because the object is generated in the Javascript Proxy it becomes available on the client. Now we can write code like:

var house = new Business.House();

But what if I want to use an object which I don’t use in my webmethodes. For example I would like to add a Room to the House object. The webservice doesn’t have a webmethod where it uses a Room object, so the JavascriptProxy will not contain a Room object. I have to make sure that the object from my Business Layer will be available through the Javascrit proxy. This can be achieved by using the [GenerateScriptType(typeof(Room))] Attribute. With this attribute you specify that the server type must be generated into the Javascript Proxy. So let’s take a look at the proxy again now i have added this attribute to my Webservice Class.GenerateMultipleClasses

Right now I have the Room and House class available on the client. See the final screenshot

House with Room

Using objects on your client can reduce data tranfsers. You can create the objects on the client and when you are happy with it send it back to the server where it will be processed. I think this is a pretty cool and strong feature of the Javascript proxy which is mainly responsible for this feature. 

by Thomas Erl 

The last few weeks when i had some time i was reading the book SOA Principles of Service Design by Thomas Erl. I really enjoyed reading his book. I wanted to know more about SOA because on my last project we touched some of the issues you could ran into when working with multiple products which must communicate with each other through webservices. SOA is a word which is used very often but i couldn´t see what it´s all about. The Book of Thomas is a very nice book to read when you want to learn more about SOA. I read some comments about the books and these were made by Senior architects and developers with a lot of experience and they all were very entousiastic about the book, so i decided that this was the book who will lead me into the worl of SOA.

The book is devided into 4 parts:

  • Part I Fundamentals
  • Part II Design principles
  • Part III Supplemental
  • Part IV Appendices

Before he starts with the fundamentals part he gives you a case study. This case study will be used to describe how a company implemented each Design principle and what kind of choices they made. I think this case study is very helpful to complete each chapter. In the Appendices you will see the final solution of the case study. After the case study Thomas starts very basic where he is explaining how the book is organized what kind of symbols he is using and what they mean. He describes what kind of Design fundamentals you got and how there are related to each other. The Fundamentals he is talking about are:

  • Design Characteristic
  • Design Principle
  • Design Paradigm
  • Design Pattern
  • Design Pattern Language
  • Design Standard
  • Best Practice

He describes three kinds of service models which he sometimes will refer to when he is describing the design principles. The three service models that are classified are:

  • Task services
  • Entity Services
  • Utility services

These three service models exist in there own logical service abstraction layers. Because these service models have there own responsibility when you compose services to support one kind of task, you can understand that all the design principles have different effect on these models. When there is a difference between these models in combination with the design principles Thomas is explaining how the principle will have effect on them. 

At the end of the fundamentals part he introduces the principles he will explain step by step in the second part of the book. The Design principles he describes are:

  • Standarized Service Contract
  • Service Loose Coupling
  • Service Abstraction
  • Service Reuseability
  • Service Autonomy
  • Service Statelessness
  • Service Discoverability
  • Service Composability

When i saw these principles for the first time i thought why is Service reuseability and Service Composability divided in 2 principles? When you use a service in multiple compositions you are reusing them right? Well you have to read until chapter 13 where Thomas answers that question because they can live without each other :).

All these design principles have sometimes strong and sometimes weak relations with each other. There are a lot of things you will have to ask yourself if you want to implement a good service inventory which will give you a huge benefit along the way. Thomas makes this very clear to the reader. He describes the benefits and the risks you are taking when implementing one of the design principles.

In the third part of the book he is comparing Object-Orientation with Service-orientation. He compares the principles of object orientation with the principles of service orientation. Here you will see that a few of the principles of object orientation will also be used in service orientation. Another chapter in the third part of the book will give some pratices about how to use Service profiles vocabularies and roles within a SOA project.

I definitely recommand this book to every developer who is willing to learn more about SOA. Even if you are new in the SOA-World. It was pretty easy to read and gives you a clear understanding of SOA. Because i liked this book so much i also ordered “Web Service Contract Design for SOA” (also written by Thomas Erl). In this book he will give the technical details.

Regards,

Dennis

Volta and Services

Today i read a nice article about Volta. In a very short sentence: Volta is a technolgy which will arrange tier splitting (Client-Server) for you. If you want to know more about Volta you should go to there site. One thing i liked very much is there opion about making request to a webservice. When you invoke a webservice from the client you use the XMLHTTPRequest object and when requesting it from the server you use System.Web.HTTPRequest object. A question mentioned on there site: Why should code that accesses services depend on where the code is running? aaaaaaah yeah. Never thought about it :(. Well they decided when you are building a Volta Application there is only one way to do it. It doens’t matter where the code runs. Pretty nice. Check the post out. Scroll down to the last paragraph “Invoking Services”.

Astoria

Hi all,

Today i had my first introduction into Astoria. Let me quote the goal of Astoria from the document i downloaded from Microsoft:

“The Goal of Astoria is to facilitate the creation of flexible data services that are naturally integrated with the web”

I think the document of Microsoft (Pablo Castro) gives you a very good introduction what Astoria will arrange for us. The only thing i like to add is. If you are a programmer with love for AJAX or Silverligth technology you should definitly check Astoria.

Older Posts »