WCF Service References not generating web.config client endpoints and bindings

by Tom Hundley 7. December 2011 14:57

Problem

I hate to admit it, but I spent a few hours pulling my hair out on this one.  I created a new WCF Service and added a few services.  I then added a service reference to some small consuming applications and everything worked fine.  I then added a service reference to a large website which has about ~50 referenced assemblies.  This time when I did it, my web.config serviceModel section wasn’t updated by Visual Studio 2010.  Normally, Studio will generate bindings and client end points for you.  What the hell!  I was baffled. 

I soon discovered that the website wouldn’t compile with this WCF service reference either, which was odd because I obviously hadn’t written any consuming code for it yet.  The compiler error was this:

 

Parser Error Message: Reference.svcmap: Failed to generate code for the service reference XXXXOrderService'.
Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension:

System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Could not load file or assembly …
 

 

Solution

As it turns out, the problem was happening because Reuse types in all referenced assemblies was enabled in the service reference settings, which is is enabled by default.  Well, that wasn’t WHY the error was occurring and I haven’t taken the time to become well versed enough in this matter (behind on a deadline), but this can apparently cause issues if both the consuming application and the WCF service reference the same assemblies.  I didn’t actually spend the time figuring out which assembly was causing the problem, but that wouldn’t matter to you anyway.  I simply unchecked Reuse types for now and everything started working; I deleted the service reference, re-added it, and the web.config was properly updated with the client endpoints and service bindings.  Badda Boom.  Service Model happiness.

If you don’t know how to get to this, you can either click the advanced button when adding the service reference or configure after it’s been added by clicking Configure Service Reference on the svcmap. 

Untitled-1

I hope this helps someone.

Happy coding,

Tom Hundley

Tags:

Visual Studio | WCF

Team Explorer 2008 and TFS 2010

by Tom Hundley 21. July 2011 08:35

Forward Compatibility Update

Imagine a hell where you’re forced to use VS 2008 in 2011. Such is my life right now. It’s not all bad, however, because we’re implementing TFS 2010. I discovered some nuances getting Team Explorer 2008 to work with TFS 2010.

 

The standard steps are these:

 

  1. 1. Install Visual Studio 2008 Service Pack 1 (VS 2008 SP1)
  2. 2. Install the Visual Studio Team System 2008 Service Pack 1 Forward Compatibility Update for Team Foundation Server 2010 (Installer)

 

Easy enough. Here are the nuances.

 

Unable to connect to this Team Foundation Server

To connect to TFS, you have to use the full URL as the server name. If you don’t and you just use the server name, you’ll get this:

 

TFS31002: Unable to connect to this Team Foundation Server.

Possible reasons for failure include:
- The Team Foundation Server name , port number or protocol is incorrect.
- The Team Foundation Server is offline
- Password is expired or incorrect

 

image

 

Solution

So, instead of using “SERVERNAME” as the server name, include the full URL which by default would be:

http://SERVERNAME:8080/tfs and you should be able to connect with no problem.

 

Unable to switch servers at this time. The Team Explorer is busy.

In addition to this annoying error (you’ll get it for each Team Project you choose), work items are not available in Team Explorer. WTF! This happens when you include a "/” at the end of your URL.

 

image

 

Solution

Remove the forward slash from your server’s URL and badda bing, it work’s like a champ. A big thinks to “Uglybugger” for posting this fix here.

 

Works: http://SERVERNAME:8080/tfs

Doesn’t work: http://SERVERNAME:8080/tfs/

 

Hopefully this helps someone, although I can’t imagine there are many people left on this planet still using VS 2008.

 

Happy Coding,

Tom Hundley

Tags:

Team Foundation Server | Visual Studio

Using Web.config Transforms to make multi-environment deployments easy

by Tom Hundley 19. May 2010 12:51

When tasked with configuration management responsibilities, you normally have several environments to which you must deploy your systems and most often, your web.config files have different information for each environment.  Several approaches have been used to address the problem this situation creates such as using T4 (Text Template Transformation Toolkit) or simply creating a separate configuration file for each environment.  I’ve personally used the latter most often as it is a quick and simple solution to the problem and works well for Click Once deployments too.  The challenge with this, however (especially in a team environment), is keeping the config files in sync when you add or change something- most developers forget to update the rest of the files and then deployments become a nightmare.

 

Enter the wonderful world of Web.config transforms.  In the spirit of keeping this short, I’m not going to cover everything about how the transforms work.  There is great reference documentation from Microsoft here: http://msdn.microsoft.com/en-us/library/dd465326(VS.100).aspx

 

We have to start with a quick overview of Web Projects.  When building web applications with Visual Studio, there are two types of projects one may chose:  Web Application or Web Site.  A discussion on which type of project is “better” is a matter for another day.  A great article exploring this question may be found here: http://vishaljoshi.blogspot.com/2009/08/web-application-project-vs-web-site.html

 

A quick summary of the some important points, however, is this.  Web Sites do not require precompilation and may therefore be updated “on the fly” allowing for quick hot-fixes in production environments.  It is, of course, debatable as to whether or not that is a good thing.  The downside is they don’t take advantage of Web.config transformations and all of the other great tools Microsoft is making available like the Web Platform Installer.  Web Applications, on the other hand, do take advantage of many of these great tools.  The downside is that you must recompile the code if you make any changes making debugging a bit more cumbersome and and quick fixes require full blown deployments.  Again, there are many merits and many flaws to both choices, but I want to review the wonderful new world of Web.config Transforms found in Web Application Projects.

 

 

Publish Profile & Configurations

Web Application Projects have a new Profile feature in the Publish functionality.  Right click on the project and chose Publish, like so:

 

image

 

image 

 

There are two important aspects to this example: 1) Profile Name and 2) Build Configuration.  I’m not going to talk about all of the Publish Methods available because this too is a topic for another post.  For now, my publish method of choice is “File System”.

 

Profile

Simply create a profile for each of your environments.  Visual Studio stores these in a publish.xml file and are kept locally.  You can add these to source control of course if you want to make them available to your team.  The way I use the File System methodology is this:  “Dev” Profile = UNC path of the website on the dev server, “Test” Profile = UNC path of the website on the test sever, etc.

 

image

 

Configuration

Let’s assume for this example you have 4 environments: 1) Local Dev, 2) Development, 3) Testing, and 4) Production.  Use the Configuration Manager to create a Configuration for each of your environments.  “Debug” works for Local Dev and “Release” works for Production, so let’s create two new configurations for Dev and Test.  Note that my “Dev” environment is a development server, not my local machine.

 

image

 

Config Transforms

Now that that we have Configuration for each of the environments, it’s time to add the transform files to the web.config.  Right click on your Web.config file and you’ll see a spiffy option called “Add Config Transoms”.  Click this and poof, Visual Studio will add transforms for each of your new Configurations.

 

image

 

The result:

 

image

 

Refer to the MSDN article for full details of the transform language, but it’s quite simple to replace data.  The easiest things to do are matching a specific key (such as a connection string) or replacing an entire element.  The greatest thing about Web.config transforms is that you only need to keep the deltas in the transform files, but using replace works well if you don’t want to learn the fine points of the transformation language (I use this for my Enterprise Library configuration blocks).

 

Replacing a Connection String

Replacing a connection string is done like this (forgoing the obvious discussion of how connection strings should always be encrypted):

<add name="Axapta.Data.Properties.Settings.AxaptaConnectionString" 
connectionString="Data Source=XX;Initial Catalog=ax50_test;uid=XXX;pwd=YYY!@#QWE"
providerName="System.Data.SqlClient" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
 

Replacing an entire Element

<loggingConfiguration name="Logging Application Block" tracingEnabled="true"
defaultCategory="" logWarningsWhenNoCategoriesMatch="true"
xdt:Transform="Replace">
        ...
</loggingConfiguration>

 

image

 

Deploying

Once you get everything setup, you’re basically done.  Now when you use the Publish functionality, Visual Studio will apply the transforms to your deployed Web.config based on your active configuration.  Thus, deploying becomes a three step process: 1) Select your configuration in the Configuration Manager, 2) Select your Profile in the Publish Tool, and 3) Click Publish!

 

GiddyUp, EzPz, etc…  <enter choice words of happiness here>

 

One might be able to write a small book on the topics covered in this article, but hopefully I kept it short and sweet so you can use it to get jump started or as a quick reference.

 

Happy coding,

 

Tom Hundley

Elegant Software Solutions, LLC

Tags: , , ,

ASP.Net | Visual Studio