Friday, January 20, 2006

WCF: A self-hosted service with multiple endpoints

Last night I started playing with more more interesting things in WCF (multiple endpoints) and I kept running into a wall: how do you set more than one http endpoint on the same service!? Nothing I was doing was working, then I ran into Indigo Girl's WCF book chapters online (see my next post). Her examples clearly explain what I was doing wrong. Let me explain how to do what I wanted to do in my own words...



Instead of having a different "server" for each endpoint of the same address scheme (i.e. http), you have a a base address for and then give each a name. There is one WSDL for all the endpoints of a service. That is: one service, one WSDL; not one endpoint, one WSDL. This stems from the fact that by default there are two endpoints repackages: mex and HTTP Get. The HTTP get one is the one that will help out with the WSDL.



Here is the fixed up code. By running this up and generating the proxy, we are able to have the complete mechanism for communication from the client to the service, including the configuration file (below).



Program.cs
Uri httpUri = new Uri("http://localhost:8081/");
using(ServiceHost hService = new ServiceHost(typeof(DemoService), httpUri)) {
hService.AddServiceEndpoint(typeof(IDemoService), new BasicHttpBinding( ), "BasicService");
hService.AddServiceEndpoint(typeof(IDemoService), new WSDualHttpBinding( ), "DualHttpService");

hService.Open( );

Console.WriteLine("Listening...");
Console.ReadLine( );
}


client app.config

<system.serviceModel>
<client>
<endpoint
address="http://localhost:8081/BasicService"
binding="basicHttpBinding"
name="BasicHttpService"
contract="IDemoService" />
<endpoint
address="http://localhost:8081/DualHttpService"
binding="wsDualHttpBinding"
name="DualHttpService"
contract="IDemoService" />
</client>
</system.serviceModel>


Even when using entitely different protocols (the higher level http and say the lower level tcp), you have one WSDL. Of course in this case, since there are more one address scheme (http and net.tcp), you have more than one base address; one per scheme.

Program.cs
Uri netTcpAddress = new Uri("net.tcp://localhost:8080/");
Uri httpAddress = new Uri("http://localhost:8081/");
using (ServiceHost service = new ServiceHost(typeof(DemoService), new Uri[] { netTcpAddress, httpAddress })) {
service.Open( );

Console.WriteLine("Listening...");
Console.ReadLine( );
}


server app.config

<system.serviceModel>
<services>
<service type="WcfDemo.DemoService">
<endpoint
address="NetTcpService"
contract="WcfDemo.IDemoService"
binding="netTcpBinding"
/>
<endpoint
address="DualHttpService"
contract="WcfDemo.IDemoService"
binding="wsDualHttpBinding"
/>
</service>
</services>
</system.serviceModel>


client app.config

<system.serviceModel>
<client>
<endpoint
address="net.tcp://localhost:8080/NetTcpService"
binding="netTcpBinding"
name="NetTcpService"
contract="IDemoService" />
<endpoint
address="http://localhost:8081/DualHttpService"
binding="wsDualHttpBinding"
name="DualHttpService"
contract="IDemoService" />
</client>
</system.serviceModel>


As you can see WCF really allows for some pretty powerful scenarios...




Monday, January 16, 2006

User Control Error: The base class includes the field 'xxx', but its type (yyy) is not compatible with the type of control (zzz).

I'm not a huge user of user controls, but today I was porting an ASP app over to the real world and I figured the particular scenario I was working with didn't really warrant the power of a server control. So after I went an took the 12 seconds out of the day to create a user control all was well. It was working beautifully and all that jazz...until I published the website to the test server!




The base class includes the field 'cltFemaleItems', but its type (Items)
is not compatible with the type of control (ASP.items_ascx).


WHAT!!!! I'm marking this one as an ASP.NET 2.0 bug. After a bit of searching online I realized that there aren't really ANY workarounds to this online.



I went back and read the message again and noticed this small hint: "( ASP.items_ascx)". Below is what my user control class declaration looked like and what the declarative directive looks like. Everything looks fine...



<%@ Control Language="C#" AutoEventWireup="true" CodeFile=" Items.ascx.cs" Inherits="Items" %>

public partial class Items : System.Web.UI.UserControl


Based on the error message hint, however, changed the name of the contro. Here is what I changed the above code to...



<%@ Control Language="C#" AutoEventWireup="true" CodeFile"Items.ascx.cs " Inherits="items_ascx" %>

public partial class items_ascx : System.Web.UI.UserControl


Then I republished and viola! All it well... That's one really weird ASP.NET 2.0 bug. Anyhow, this workaround seems to work well.

Tuesday, January 10, 2006

Video 2 (FWD) - "Introduction to the Firefox JavaScript Console"

Firefox comes with many incredible utilities right out of the box. One of these tools is the JavaScript console. Most developers who have done any web development at all utilizing Firefox has used this great tool, but few know of some of the more powerful features. In this video I touch lightly on a few features that you may have overlooked.



In the next video we will dive hard core into some code to see the Firefox Web Development suite in action.