Running WCF on IIS 5 (Windows XP)

After running WCF on my Vista laptop (IIS7) I needed to deploy the application on some Windows XP computers. Again some strange errors occurred:

[code:html]

Error Description: "This collection already contains an address with scheme http.  There can be at most one address per scheme in this collection.
Parameter name: item"

[/code]

The problem is that WCF cannot handle more than one identity (host headers) per website. At first I configured IIS to have one HostHeader. That solution was just to dirty. So I kept on searching the internet.


You can fix this problem by adding prefix-key(s) in the baseAddressPrefixFilters section of the Web.Config:

[code:xml]
<system.serviceModel>
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
        <add prefix=”http://www.local.develop”/>

</baseAddressPrefixFilters>
</serviceHostingEnvironment>
</system.serviceModel>
[/code]


Hope this helps.


Sources:
http://geekswithblogs.net/robz/archive/2007/10/02/WCF-in-IIS-with-Websites-that-have-Multiple-Identities.aspx
http://blogs.msdn.com/rampo/archive/2008/02/11/how-can-wcf-support-multiple-iis-binding-specified-per-site.aspx

Asp.Net: Databinding a array of strings

You can use a string array as datasource and view the string values by using the Container.DataItem property.

Code example

Codebehind:

[code:c#]

string[] testData = {"1","two","3","4"};
rptDemo.DataSource = testData;
rptDemo.DataBind();

[/code]


And in the .aspx:

[code:html]

<asp:Repeater runat="server" ID="rptDemo">
    <ItemTemplate>
        <%# Container.DataItem %>
    </ItemTemplate>
</asp:Repeater>

[/code]

Linq to Sql: Retrieve properties from related data (LoadWith)

You have to specify which related-data you want to retrieve from a object so you can access them outside the Linq data-context. You can achieve this by using the LoadWith method of the DataLoadOptions Class. The LoadWith method accepts an lambda expression that specifies which object you want to retrieve.

In the following example I have a employee table that has a relation with the company table. In my code I want to show the employee with the company name (outside the DataContext).


Employee employee;

using (LinqDataContext db = new (LinqDataContext())
{
   DataLoadOptions dlo = new DataLoadOptions(); 
   dlo.LoadWith(e =&gt; e.Company);
   db.LoadOptions = dlo;

   employee = from item in db.Employees
                      select item).First();
}

string companyName = employee.Company.Name;


Because of the DataLoadOptions I can now use the company properties to print the company name outside the DataContext.

Enjoy.

Membership: Update Password MembershipUser (ChangePassword)

You can change the password of a MembershipUser object in C# with the ChangePassword method. The only problem of this method is that it needs the old password(string) as input parameter and I only have the hashed version off the password. To get the old password you can user the MembershipUser.ResetPassword() method. This method will reset the password and returns the new password as string.



MembershipUser user = Membership.GetUser(userNameTxt.Text);
user.ChangePassword(user.ResetPassword(), passwordTxt.Text);


Don’t for get to check that the enablePasswordReset setting is true in the web.config.

[code:xml]

    <membership>
      <providers>
        <remove name=”AspNetSqlMembershipProvider” />
        <add name=”AspNetSqlMembershipProvider” type=”System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”
        connectionStringName=”SiteSqlServer”
        enablePasswordRetrieval=”false”
        enablePasswordReset=”true
        requiresQuestionAndAnswer=”false”
        applicationName=”/”
        requiresUniqueEmail=”false”
        minRequiredPasswordLength=”3″
        minRequiredNonalphanumericCharacters=”0″
        passwordFormat=”Hashed”
        maxInvalidPasswordAttempts=”5″
        passwordAttemptWindow=”10″
        passwordStrengthRegularExpression=””/>
      </providers>
    </membership>

[/code]

Goodluck!

Microsoft Tag: Snap my vCard

When surfing the internet I start reading about Microsoft Tag Beta (of course). With Microsoft Tag you can create links with a image-pattern. The image-pattern can be decoded to a link with the Microsoft Tag program on your Windows Mobile (with camera).

You can create graphical image-patterns with the following actions:

  • Link to an URL
  • Free text
  • vCard
  • Dialer

It looks very promising. Not every tag on a screen gets recognized at once, but the printed tags work very well.

I've placed my vCard in a tag on my blog. Just try to tag it 😉