Far Away Developer

Sebastien Lachance

Archive for the 'WCF' Category


WCF : Problems and Solutions

Posted by Sebastien Lachance on May 22, 2008

This is a list of various errors you may encounter when working with WCF (Windows Communication Foundation).

Could not find a base address that matches scheme http for the endpoint with binding BasicHttpBinding. Registered base address schemes are [].

Add to your service :

<host>
     <baseAddresses>
          <add baseAddress="http://localhost/MyService"/>
     </baseAddresses>
</host>

 

No set method for property ‘Message’ in type ‘MyProject.MyType.

A DataContract can’t have a property with no set method (http://msdn.microsoft.com/en-us/library/ms733127.aspx). However, you can use a private set accessor if allowing modification of the property is prohibited. :

[DataMember]
public object Message
{
    get { return _message; }
    private set { _message = value; }
}

 

HTTP could not register URL http://+:80/MyService/ because TCP port 80 is being used by another application.

Happen if IIS is running (very likely!). Change the port to another one. Example :

<host>
     <baseAddresses>
         <add baseAddress="http://localhost:8080/MyService"/>
     </baseAddresses>
</host>

 

The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.

You have an error, but you don’t get all the details. To get them :

<behaviors>
    <serviceBehaviors>
       <behavior name="BasicBehaviorConfiguration">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
       </behavior>
    </serviceBehaviors>
</behaviors>

 

Technorati Tags: ,

Posted in .NET, WCF | No Comments »

Type Sharing in Visual Studio 2008

Posted by Sebastien Lachance on May 22, 2008

On a previous post called Reality of type sharing in WCF. I talked about a way to use existing types for a WCF service instead of the generated proxies. Previously, we were unable to do that in Visual Studio 2005, but it’s doable Visual Studio 2008.

Start by adding the library you would use for type sharing on the project you will add a service reference.

When you add a service reference, click on the Advanced… button.

addservicereference

 

Then, make sure the Reuse types in referenced assemblies checkbox is checked.

reusestypes

You can fine tune further, if you do not want to use some assemblies for type sharing.

And you are done!

Technorati Tags: ,

Posted in .NET, Visual Studio, WCF | No Comments »

Visual Studio 2008 - WCF Templates

Posted by Sebastien Lachance on May 21, 2008

When you want to create a new WCF project, you are presented with 4 different templates to use :

  • Sequential Workflow Service Library
  • Syndication Service Library
  • State Machine Workflow Service Library
  • WCF Service Library

Each one has it’s own particularities. It’s important to know which one to choose but you should know that the template only generate things you need to get started. You can always start from an empty WCF Service Library and build on top of it. Anyway, here is an explanation for each one.

 

Sequential Workflow Service Library

You basically create a sequential workflow project that made operations available by WCF. I have no experience with Workflow Foundation so I will not go further into details.

 

Syndication Service Library

This template is great. It present you a way to expose an RSS or Atom feed via a WCF Service contract. This is built-in stuff already present in the framework.

To expose a feed, you need an operation that return a  SyndicationFeedFormatter (in the System.ServiceModel.Syndication namespace). Then create a SyndicationFeed and add SyndicationItem to it. Finally, create a Atom10FeedFormatter or Rss20FeedFormatter and return it.

SyndicationFeed feed = new SyndicationFeed("Feed Title", "A WCF Syndication Feed", null);
List<SyndicationItem> items = new List<SyndicationItem>();

// Create a new Syndication Item.
SyndicationItem item = new SyndicationItem("An item", "Item content", null);
items.Add(item);
feed.Items = items;

// Return ATOM or RSS based on query string
// rss -> http://localhost:8731/Design_Time_Addresses/SyndicationServiceLibrary1/Feed1/
// atom -> http://localhost:8731/Design_Time_Addresses/SyndicationServiceLibrary1/Feed1/?format=atom
string query = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["format"];
SyndicationFeedFormatter formatter = null;
if (query == "atom")
{
   formatter = new Atom10FeedFormatter(feed);
}
else
{
   formatter = new Rss20FeedFormatter(feed);
}

return formatter;

 

State Machine Workflow Service Library

Another template that expose a Windows Workflow as a Service. This time the type of Workflow is a State Machine. A state machine workflow contrary to a sequential workflow is driven by external events. Transition between states are based on certain events until it reach the final state.

 

WCF Service Library

The most basic project to create a WCF service. You can use it to do everything you want with the most control.

 

Technorati Tags:

Posted in .NET, Programming, WCF | No Comments »

Why is my object losing all of it’s values when sent through WCF?

Posted by Sebastien Lachance on January 17, 2008

Duh, this isn’t my day! Applying the DataContract and DataMember attributes to my class is a great solution to this problem. Anyway, at least I didn’t loose much time.

Posted in .NET, WCF | No Comments »

Reality of type sharing in WCF

Posted by Sebastien Lachance on November 13, 2007

I am working a lot right now with WCF (Windows Communication Foundation). I am doing the service side of the architecture. The problem we faced this week was with type sharing. Suppose you have a customer class and an address class as data contract. The customer have an address list. Then we have two services who use those types, CustomerService and AddressService. One of the service do operation with the customer and the second on the address. All this one one assembly. On a real world scenario we had to take the address of the customer we just got with the customer’s service and provide it to the address’s services.

We used Visual Studio to generate the proxies for those services. Since CustomerService and AddressService are each one aware of the 2 data contracts (Address and Customer) the call made to svcutil from Visual Studio does not generate proxies with type sharing. You have yourself two times the address class and then can’t be passed from one service to another.

But fortunately, a solution exist!

1. I had to separate the data contracts from the services contracts and puts them in a new assembly.

2. Do not ever use Visual Studio to add service reference (this is what will get you 2 times the same class in 2 different namespaces ).

3. Learn to use svcutil. Then learn about the /r: switch. When using this switch, you can specify which assembly to use when resolving reference.

The 2 downside I see, is that you can’t use Visual Studio anymore to generate proxies and that you need to control both side (service and client). Or at least the service side and provide the data contracts assembly to your client.

Posted in .NET, WCF | 1 Comment »