Feeds:
Posts
Comments

The last few days i’ve been working on a WCF service which is using a few other service as sources. One of the source is the crmservice. Somehow when i was programming against the crmservice everything went smooth when i was testing it in the development server of Visual studio (Cassini). When i deployed the WCF service on a webserver in IIS the service was performing very poor. The CPU and the memory was rising sky high. It took me a while to figure it out, but a colleague of my pointed me to a very good post which was a start for solving my problem. I am not a CRM guru, so this post is maybe for some of you old news but you have to check this post of the CRM team. Down in the comments someone has a step by step description. You can find it here. Hopefuly you don’t have to spent to much time solving this issue.

Regards

In VSTS 2010 Microsoft has a pretty cool feature called “gated check-in”. This will prevent a check-in if it will break the build. Brian Harry mentioned this on his blog.

Regards

Relations in CRM 4.0

Hi all,

I am working on a project where i am implementing CRM 4.0. One of the demands of our customer is that they want to create relationships between Account entities and they want to store some additional information about this relationship. They want to add a startdate and an enddate attribute to the relationship entity. Well the relationship entity which is delivered out-of-the-box doesn’t give us any options the extend the entity with extra attributes. This means that we have to create our own relationship entity. Well in our situation we want to create N:N relation between the Account entities, which means we have to make the following relations:

Primary entity Relation Secondary entity
Account 1:N CustomRelation
Account 1:N CustomRelation

We have to add this type of relation twice otherwise we can’t make a N:N relation between Accounts. So far so good, what does this mean for our CRM interface. In the left menu you will see a link to Customrelationship Entity twice. This is something you don’t want.

CRM relation

The first link will show us the relationships where the selected Account is the primary entity in the relation and the second link will show us the relationships where the selected account is the secundary entity in the relation. So if we implement it in this way we don’t have an single view of all the relationships from one Account.

My Colleague Ronald Lemmen told me that this should be fixed with building a plugin. The plugin will be responsible for created a relationship the other way around. For example:

Organization A –> Organization B: this relationship is made in CRM.
Organization B –> Organization A: this relationship is made by the plugin.

This solution will result in 2 relationships between the same entities. CRM itself is using the same solution. See below. In the first screenshot we see that Avanade is the selected Account. Avanade is also Party1 in the relationship with Microsoft.

CRM relation

In the screenshot below we see the same relationship but the parties are reversed. Micorsoft is the selected account and Party1 in the relationship.

CRM relation

Now that we create a reversed relationship with our plugin we are able to remove one link in the menu (see first screenshot). This can be done in the screen where you add your relations between entities. I hope that this post will help other developers who are running into the same problem.

Kind Regards!

The last 2 days I have been testing a little piece of VSTS 2010. Something I liked is the way VSTS 2010 supports TDD. A lot of developers are familiar with TDD, some hate it and some love it. I don’t have a lot of experience with TDD, but I am very interested and tried this way of programming on my last project. Test-First development is something which makes you look different to your own code. I realized that I was focused even more on the signature of the method that I was writing. What are good input parameters and what are my return values.

When you start writing your first Unit test you will run into the annoying thing that every class you instantiate isn’t available yet. Well in VSTS 2010 the class is still not available, but there is a very simple way to make them available without losing the focus on your Unit test. See the screenshot below.

Generate class 

In this screenshot you see that the class which is giving an error because it doesn’t exist has a new option to create the class for me. You have 2 options:

  • Create the class directly in the project where the Unit test resides
  • Create the class in another project of your own choice

I think the second option is the best option, because you don’t want all your classes in the same project with all your test files. When you click on the section option (Generate other…) you will get the following panel.

Enter class information

As you can see in this panel you are able to select the following things:

  • Access modifier (Default, Public, Private, Internal)
  • Type (Class, Struct, Interface, Enum)
  • Project location (The project where you want the class to be created)
  • File name: (The name of the file)

Something what is missing is the opportunity to enter a namespace where the class should belong to. Default the class will belong to the same namespace where the unit test belongs to. Hopefully Microsoft will fix this before the release VSTS 2010. I changed the project location to another project because I don’t want my classes inside my test project. When you create the class in another project VSTS will automatically add a reference to the project where the class will be created.

Solution Explorer

Well the unit test isn’t finished yet. In my Unit test I want to test a method which multiplies the incoming parameter. So I need a method with the following signature:

  • Name: Multiply
  • Input parameter: int
  • Return parameter: int

I write this method down in my Unit test in a way it should be invoked if it exists.

New method

You can stub this method without leaving you Unit test. When VSTS creates a stub for me, it will implement the method with throwing a NotImplementedException. This is fine for me, because it doesn’t matter if the first run of my Unit test will fail. At the end the unit test will look like this.

Unit Test

The class which is generated for me will look like this.

Generated class

As you can see in the screenshot, the Multipy method is created with the right signature and it will throw an exception. The namespace isn’t correct like I already mentioned. The next thing to do is write functional code which will make the unit test pass. So test first development is something which is simple to do in VSTS 2010. When VSTS 2010 is released we are able to write our code in combination with unit tests in two ways:

  • Write our functional code first and generate a Unit test based on the class
  • Write a unit test and generate a class which supports those functionalities you are looking for

When this version of VSTS is released i am happy to do some TDD.

Microsoft is developing some pretty cool visualization features for branches. Sometimes it’s hard to explain to developers how you want to work with branches. You have a branch for the code base which is running right now on the production server. In case you get some bugs in production which should be fixed quickly, just switch to your production branch and fix the bug. Well when i got a bug in my production branch it’s also in my development branches. I should merge the bugs fix back to my developement branches. You can imaging that knowing which code runs where is pretty hard on a project with multiple branches.

There are whitepapers for branching strategies. When should i make a branch? when must I merge my development branch to the production branch. Which features are available in which branch. With the new visual tools coming in VSTS2010 this is very well organized. You have to check the following screencast on Channel9. Enjoy!

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

Older Posts »