Here I will post problems I and my colleagues met and solutions we found.

Showing posts with label WCF. Show all posts
Showing posts with label WCF. Show all posts

Wednesday, June 24, 2009

This element is not currently associated with any context

When debugging WCF you can see this exception. Some people advice to just disable stop on exception But it's useful feature.

The better is to go into details of this dialog and disable just this specific exception. The only small problem is that it's not in the list. But it's really a small problem. You can add it.

Just press "Add..." button, choose "Common Language Runtime Exceptions" from the drop down list and type the exception type, which is System.Configuration.ConfigurationErrorsException. Now you can disable stopping on just this exception and not all of them.

Wednesday, June 03, 2009

WCF - nullable values are not working in generics

Today I spent couple of hours figuring out why I suddenly got an error "Referenced type 'x`1, ... with data contract name 'xIF_Ph6aZR' in namespace 'x cannot be used since it does not match imported DataContract. Need to exclude this type from referenced types."

It was working and what I did just little bit of re-factoring. What I found is that there is a combination of conditions that does not work, while every one of them works separately:

  1. Generic class is used as DataContract.
  2. This class has nullable DataMember property
  3. You want to reference your class in your client instead of creating in through wsdl.

[DataContract]
public class DummnyContract<T> where T: IBusinessObject
{

[DataMember]
public DateTime? LastModified{get;set;}

}
and then you use it like this:


[ServiceContract]
public interface IService
{
[OperationContract]
DummyContract<int> Get(int id);

}

This just does not work when you reference your assembly with declaration of this class. You can have it without class being generic. Or, you can have generic without nullable property. But not together.

Friday, April 24, 2009

WCF under IIS access problems

Today I spent few hours trying to resolve problem with our WCF server for one of our clients. Somehow everything went wrong. Our configuration is WCF server that utilize .NET 3.5, and I set it up to work under IIS6.

The errors I got were different, but in result it was all about setting permissions for IIS. Many of them were trivial, but the last one I found tricky. HTTP result code was 500, internal server error, the error in EventViewer said: Could not load file or assembly 'System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=xxx or one of its dependencies. Access denied.

Logically, something was wrong with access to \WINDOWS\Microsoft.NET\Framework\v2.0.0.527 folder. However, it was not so. What helped me was adding NT permissions to the folder with my WCF server to the group IIS_WPG. And this is after I tried to add permissions to user ASP_NET… and IUSR_… without success.

Sunday, February 15, 2009

Implementing netTcpBinding in WCF and security

Usually I post when I solve some problem. I didn't solve this one yet, but was almost there.

We decided to build n-tier application using CSLA. So, this is a desktop WPF application, we just host a server with business objects and desktop client access the server through Internet. I wanted to use WCF for communication. Also, I wanted to host it in my own windows service, not by IIS. Additionally, I wanted to use TCP binding, as it is supposedly faster, if I understand correctly, which is another reason to not use IIS.

It looked very simple, like all I had to do is to change binding to NetTcpBinding. And first, it worked fine until I tried to connect from my home computer, which wasn't member of our Windows domain. It looked that for some reason connection was terminated by the host. The error message did not give me any specifics. Using SvcTraceViewer.exe I identified the problem as related to the security.

Making the long story short, I found this blog post to be the best to help me with my problem. The last step of getting certificate value did not work for me, and the project is on hold now. I hope I will find the time to resolve everything.

Now, let me explain in few words what the problem is. All bindings with exceptions of BasicHttpBinding require some kind of security on the transport level. So, we have to create certificate and apply it somehow. We could register it in the Windows, but I didn't want to go this way.

Another problem is authentication. If I hosted service under IIS, that would provide some mechanism, but this is not what I wanted. To help with that I decided to use custom username authentication. And this is also covered very well in post I found.