Fresh installation of IIS doesn’t recognize .svc requests

This problem can be solved easily by running the ServiceModelReg tool. This can be found in %SystemRoot%\Microsoft.Net\Framework\v3.0\Windows Communication Foundation.

ServiceModelReg –i will do the trick.

More information at http://msdn.microsoft.com/en-us/library/ms732012.aspx

Technorati Tags: ,,,

Posted in Geen categorie | Leave a comment

MS Access has a problem with date/time fields when the Milliseconds aren’t 0.

I was trying to add a record with a date/time field in an MS Access database like this:

const string UpdateContactPersonSQL =
    "UPDATE ContactPerson set Firstname = ?" +

   […]

        ", ModificationDate = ? " +
    "WHERE ContactpersonID = ?;";

int affected = 0;
Database db = DatabaseFactory.CreateDatabase();

using (DbCommand cmd = db.GetSqlStringCommand(UpdateContactPersonSQL))
{
    Contact.ModifiedBy = UserID;
    db.AddInParameter(cmd, "Firstname", DbType.String, nz(Contact.Firstname));

[…]

     db.AddInParameter(cmd, "ModificationDate", DbType.DateTime, DateTime.Now);
    db.AddInParameter(cmd, "ContactpersonID", DbType.Int32, Contact.ContactpersonID);

    affected = db.ExecuteNonQuery(cmd);

}

Access doesn’t like the use of DateTime.Now, because it can’t handle the Milliseconds field when it’s not 0. So I wrote (copied) a little helper function to return Now with the Milliseconds set to 0:

protected DateTime Now()
{
    DateTime dtmDate = DateTime.Now;
    return new DateTime(dtmDate.Year,
                        dtmDate.Month,
                        dtmDate.Day,
                        dtmDate.Hour,
                        dtmDate.Minute,
                        dtmDate.Second);
}

and of course I pass Now( ) instead of DateTime.Now. It’s working 🙂

Ref: http://forums.asp.net/t/1079456.aspx

Tags van Technorati: ,,,

Posted in Development | Leave a comment

MIME Type Detection in Internet Explorer

Just a quick one: here you can find the possible values for Response.ContentType, like:

Response.ContentType = "application/x-zip-compressed";

http://msdn.microsoft.com/en-us/library/ms775147(VS.85).aspx

 

Tags van Technorati: ,,

Posted in Development | Leave a comment

Securing a WCF service with a username / password

When you read the MS documentation, this looks like a trivial thing to do, but of course there are always some things that just don’t work as you’d like them to work. I got it working thanks to some excellent articles:

http://msdn.microsoft.com/en-us/library/aa354513.aspx describes the major steps to create a user/password validation function, and to inform your web service of the existence of this function (web.config settings of course). Don’t forget to create the certificate that’s mentioned in the setup instructions.

Then I installed the service on a web server, and tried to start it. Even after installing the certificate I got this error: CryptographicException: Keyset does not exist Searching a bit further led to this article:

http://social.msdn.microsoft.com/Forums/en-US/Geneva/thread/24e3d00d-02b8-4541-8e5d-eb28b7e817a9 in which they say that you have to grant private key permissions to your network service account. Unfortunately they don’t describe how to do that. This article however describes it pretty well and accurate:

http://stackoverflow.com/questions/425688/how-to-set-read-permission-on-the-private-key-file-of-x-509-certificate-from-ne , using this line:

winhttpcertcfg -g -c LOCAL_MACHINE\My -s test -a NetworkService

Now only I had to find the winhttpcertcfg tool to finish my quest. It is here:

http://www.microsoft.com/downloads/details.aspx?familyid=c42e27ac-3409-40e9-8667-c748e422833f&displaylang=en 

The full script to install the certificate on the server, and grant the necessary access to it:

set SERVER_NAME=localhost

echo %SERVER_NAME%

echo ******************

echo making server cert

echo ******************

makecert.exe -sr LocalMachine -ss MY -a sha1 -n CN=%SERVER_NAME% -sky exchange –pe

certmgr.exe -add -r LocalMachine -s My -c -n %SERVER_NAME% -r CurrentUser -s TrustedPeople

winhttpcertcfg -g -c LOCAL_MACHINE\My -s %SERVER_NAME% -a NetworkService

 

Posted in Geen categorie | Leave a comment

Starting a scheduled task in C#

I had to start a scheduled task. Most of the examples on MSDN use C++ for this, because there are no managed APIs to work with the task scheduler. Lucky for me the COM components for the Task Scheduler are pretty easy to use.

The steps:

  1. Add a COM reference for the TaskScheduler component.
  2. Add   using TaskScheduler;   to your source.
  3. Use the following code as an example:

TaskScheduler.TaskScheduler ts = new TaskScheduler.TaskSchedulerClass();
ts.Connect("faq-xps", "username", "domain", "password");
ITaskFolder tf = ts.GetFolder(@"\");
IRegisteredTask task = tf.GetTask("Test");   // “Test” is the name of the task in the Scheduler
task.Run(null);              // If your task requires parameters, then pass them instead of null

BTW, if you want to do this using a command line utility, you may want to try “schtasks” in a command prompt.

Posted in Development | Leave a comment

VS 2008 – View white space

I gladly use a lot of VS’s shortcuts, and one of my favorites is Ctrl+E, Ctrl+D which will format your document.

Today I missed and typed something else than Ctrl+E, Ctrl+D, causing my editor to show all the tabs as arrows (like in Word). So I had to find how to reset this. In the Edit > Advanced menu I found the correct command (View white space), and if you’re interested in the shortcut: Ctrl+E, Ctrl+S.

Posted in Geen categorie | Leave a comment

Receiving a long response (> 64kb) from a web service (WCF client)

Tags van Technorati:

 

I’m calling a web service which returns (after a long while) a large string. This string is more than 64 KB in size, so I had to tweak the config file on the client. Here are the highlighted changes in the app.config file:

<basicHttpBinding>
  <binding name="VLSAdminSoap" closeTimeout="00:01:00" openTimeout="00:01:00"
    receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false"
    bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="655360"
    messageEncoding="Text" textEncoding="utf-8" transferMode="StreamedResponse"
    useDefaultWebProxy="true">
    <readerQuotas maxDepth="32" maxStringContentLength="81920" maxArrayLength="16384"
      maxBytesPerRead="4096" maxNameTableCharCount="16384" />

 

The maxReceivedMessageSize is by default 65536, I made this 655360. I also specified that the response isn’t buffered, but that it will be streamed. I also had to increase the maxStringContentLength.

Also notice that the sendTimeout thas been put to 10 minutes, because the service doesn’t return anything soon.

Posted in Geen categorie | Leave a comment

Using a SmartPartPlaceHolder

Tags van Technorati: ,,,

When you want to present a SmartPart like a Usercontrol, you can use a SmartPartPlaceholder. The placeholder hase a property ‘SmartPartName’ which is used to store it in a collection of the WorkItem.

This means that you must fill the SmaprtPartName property with a unique name, or the placeholder will throw an exception.

Posted in Development | Leave a comment

Showing a SmartPart in a Windows form

Tags van Technorati: ,

The easy part: create a form with a SmartPartPlaceholder on it.

Second: provide a property like this:

public UserControl SmartPart
{
    get { return (UserControl)smartPartPlaceholder1.SmartPart; }
    set { smartPartPlaceholder1.SmartPart = value; }
}

Third:

From within a presenter make a call like this:

internal void EditCompany(int id)
{
    CompanyDetailView view = WorkItem.SmartParts.AddNew<CompanyDetailView>("CompanyDetails");

    SmartFormBase frm = new SmartFormBase();
    frm.SmartPart = view;
    frm.ShowDialog();

    WorkItem.SmartParts.Remove(view);
}

This will display your smartpart inside a normal Windows form.

Posted in Geen categorie | Leave a comment

Deploying a SCSF Application

First attempt: right click shell > Deploy, then follow the wizard.

This works, and it will allow you to deploy the files that are referenced in the Shell application. That doesn’t include any Business or Foundational modules because they’re added later (using the ProfileCatalog.xml file).

The result is that you’ll get a nice, empty shell when activating the deployed application.

So I seached further and fell on this page: http://msdn.microsoft.com/en-us/library/cc558877.aspx. It describes the different activities to be done for a complete deployment.

Step 1: publish an initial version. Done 🙂

Step 2: http://msdn.microsoft.com/en-us/library/cc558879.aspx Find the ManifestManagerUtility.exe, and use it to add the additional assemblies. It can be found here: http://www.codeplex.com/smartclient/Project/FileDownload.aspx?DownloadId=5060

It still doesn’t work. I’ll have to investigate the initial deployment again I’m afraid, I’ll keep you posted!

 

References:

Posted in Geen categorie | Leave a comment