Thursday, 30 June 2011

C# access webservice from behind proxy

I was trying to use C# .NET desktop application to access a webservice from my office, the web-service is behind a proxy firewall, I was annoyed by seeing the following error message

"- The request failed with HTTP status 407: Proxy Authentication Required"

By googling I found a solution that enables me to disable proxy "http://stackoverflow.com/questions/2131933/http-407-proxy-authentication-error-when-calling-a-web-service"

To disable the proxy, in the App.config file add the following configuration

<system.net>
<defaultProxy enabled="false" useDefaultCredentials="false">
<proxy/>
<bypasslist/>
<module/>
</defaultProxy>
</system.net>

To enable the proxy and to use the default proxy settings(specified in IE) add this configuration in your App.config

<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true">
<proxy/>
<bypasslist/>
<module/>
</defaultProxy>
</system.net>

Monday, 30 May 2011

Godaddy Email problem with hosted applications

My web application hosted on Godaddy can't send email messages after being uploaded there. But it works normally and can send email messages from my local machine. I tried many variations for SMTP configuration as follows but no-way for success:

1- This configuration is working from my local machine

· SMTP: smtp.mydomain.com

· Port: 25

· SSL: not enabled

· user: webmaster@mydomain.com

· password: **********

2- This configuration is not working

· SMTP: smtpout.secureserver.net

· Port: 25 or 80 or 3535 or 587

· SSL: not enabled

· Cedential user: webmaster@mydomain.com

· Cedential password: **********

3- This configuration is not working

· SMTP: smtp.secureserver.net

· Port: 25 or 80 or 3535 or 587

· SSL: not enabled

· Cedential user: webmaster@mydomain.com

· Cedential password: **********

I found the solution, and it was so old problem, since 2005, I found it in the following link:

http://forums.asp.net/t/939893.aspx/1?Problem+with+System+Net+Mail+on+GoDaddy

The problem is that SMTP-server is not smtpout.secureserver.net as Godaddy tells me. But It is relay-hosting.secureserver.net that nobody tells me at all. There is no need for user name or password, relay is open for 1000 message per day for hosted applications.

jQuery simplemodal plugin typeError: 'tagName' is null or not an object.

Many thanks for Eric's effort he made to create the great simple modal jQuery plugin.

http://www.ericmmartin.com/projects/simplemodal-demos/

I found a bug then fixed it, the bug is in $.modal.impl.create function , I think it is not new for you, where you mentioned the solution when you commented to use 'form' instead 'body' for the property appendTo.

First: the comment have to be modified to become {use '#aspnetForm'} instead of {use 'form'}
Second: in line number 344, there is still hard coding problem of the word 'body', as follows.

// add styling and attributes to the data
// append to body to get correct dimensions, then move to wrap
s.d.data = data
.attr('id', data.attr('id') || s.o.dataId)
.addClass('simplemodal-data')
.css($.extend(s.o.dataCss, {
display: 'none'
}))
.appendTo('body');


I replaced the hard coded word with s.o.appendTo object such like {.appendTo(s.o.appendTo);}, and everything goes right.


Monday, 28 March 2011

Firefox problem with iframe

|
|..primery.aspx
|..rootpage.aspx
|..|-l1
     |-l2
       |-l3
         |..test.htm
|

I have HTML page (i.e. test.htm) in a website say (http://172.16.16.20), the page is deeply located into a 3rd level folder, to access the page you have to write the URL as follows (http:/172.16.16.20/l1/l2/l3/test.htm), test.htm has iframe element with src="/rootpage.aspx" like following:
..
<ifram src="/rootpage.aspx"></iframe>
..

The "rootpage.aspx" with another page named "primary.aspx" are located in the root folder of the website. And primary.aspx looks like the following:

...
<iframe src="/rootpage.aspx"></iframe>
...

If you open primery.aspx , it is normal to expect to see iframe of tset.htm that contain iframe of rootpage.aspx. That is true for all browsers except Firefox. Unfortunately, Firefox will give the following error:

The page cannot be displayed
You have attempted to execute a CGI, ISAPI, or other executable program from a directory that does not allow programs to be executed.
Please try the following:
* Contact the Web site administrator if you believe this directory should allow execute access.
HTTP Error 403.1 - Forbidden: Execute access is denied.
Internet Information Services (IIS)
Technical Information (for support personnel)

I go to IIS&gt;&gt;website&gt;&gt;Properties&gt;&gt;HomeDirectory&gt;&gt;ApplicationSettings&gt;&gt;ExecutePermissions and make it Scripts and Executables. After that Firefox gave me the next error:

Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /l1/l2/l3/rootpage.aspx
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053

From the last error message I understand that Firefox iframe.src property behaves differently than other browsers, I put "/" in front of the page name to tell the browser to go to root folder, but Firefox believes that root is relative to iframe context not browser context.

To solve the problem I modifed src="/rootpage.aspx" to become src="../../../rootpage.aspx"

Now everything goes right.


Sunday, 26 December 2010

old "dbo" database owner prevents service broker from working properly - SQL 2005

I have cloned a virtual copy of Win2003 server that has SQL2005 already installed. The new server is planned to be disconnected from the domain of the original server and run separately.

 

In SQL2005 I dropped all databases and restored my database that has service broker already enabled, the restored database was running very well on another server inside my old domain "AWQAF", this database also has a notification service running on top of a message queue called "messageQueue".

 

Service broker then didn't working as supposed or as it should to work like.

 

I tried to check the status of the service broker using the following statement:

SELECT is_broker_enabled FROM sys.databases WHERE name = 'AfaqCMS';

 

It gives me 0 result, a mean of service broker is disabled.

 

So, I tried to enable service broker using the following statement:

ALTER DATABASE [AfaqCMS] SET NEW_BROKER WITH ROLLBACK IMMEDIATE;

 

By trying to SEND/RECIVE messages using the following statements, I got dialog created without messages transmission:

DECLARE @NotificationDialog uniqueidentifier;

SET QUOTED_IDENTIFIER ON;

BEGIN DIALOG CONVERSATION @NotificationDialog

FROM SERVICE ChangeNotifications

TO SERVICE 'ChangeNotifications'

ON CONTRACT [http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification]

WITH ENCRYPTION = OFF;

SEND

ON CONVERSATION @NotificationDialog

MESSAGE TYPE [http://schemas.microsoft.com/SQL/Notifications/QueryNotification] (N'CommentHits');

SELECT @NotificationDialog;

RECEIVE * FROM ChangeMessagesQueue ;

 

By checking transmission queue of the system I found some errors around the original owner of the restored database.

SELECT * FROM sys.transmission_queue

 

A filed called "transmission_status" is containing the following exception:

An exception occurred while enqueueing a message in the target queue.

Error: 15404, State: 11.

Could not obtain information about Windows NT group/user 'AWQAF\adm_walghool', error code 0x534.

 

By deleting 'AWQAF\adm_walghool' from all locations it can be existed in, I got another status:

An exception occurred while enqueueing a message in the target queue.

Error: 15517, State: 1.

Cannot execute as the database principal because the principal "dbo" does not exist,

this type of principal cannot be impersonated, or you do not have permission.

 

Now I realized that it is the database owner that prevents service broker from working properly, So I run the following statement to get every things working successfully again:

ALTER AUTHORIZATION ON DATABASE::[AfaqCMS] TO [SA]

 

Anthother statement can be used also:

 

USE AfaqCMS

GO

EXEC dbo.sp_changedbowner @loginame = N'zakauser', @map = false

 

 

 

 

Monday, 2 August 2010

What is the difference between ISO 9660, Joliet and UDF?

CD-ROM File Systems

An ISO 9660 file system is a standard CD-ROM file system. Full ISO format requires all upper case characters or numbers, no spaces, very limited special characters, and no more than 30 characters in the name.

Joliet is the name of an extension to the ISO 9660 file system. Joliet format permits 64-character file names with lower-case alpha and other relaxed restrictions. It also relaxes the ISO requirement for directory nesting to no more than eight levels. It doesn't hurt to include the Joliet Directory if the names conform.

UDF is a hybrid filesystem that uses both UDF and ISO 9660. Also called a UDF bridge, it was commonly used until Microsoft incorporated support for UDF in its operating system. UDF permits 127 16-bit Unicode characters, or 254 8-bit Unicode characters. If any character in any name is not in the list of legal 8-bit Unicode characters, all names will be represented in 16-bit Unicode.

However Joliet is no longer needed since the ISO 9660 standard has been extended in 3 different levels:
Level 1: Filename cannot be longer than 8 chars , Filename extention cannot be longer than 3 chars.
Level 2: Filename can be up to 255 chars long.
Level 3: Same as level 2 but files can be written in multiple extents (-> Packet writing).


Normally a Mac can read both ISO 9660 and Joliet CDs.

Monday, 28 June 2010

ClickOnce does not install fonts - Install fonts using C#

ClickOnce does not install fonts. ClickOnce is designed to be a non-impactful install, and installing fonts is considered impactful to a user's computer. ClickOnce is only a deployment technology, it does not offer any support for font installation, so this operation requires extra coding. We have to code the font installation logic in the application. To install font on client machines, we have to create code just like the following.

ClickOnce deloyment normally does not touch the system directories. This is an important difference with MSI deployment technology. ClickOnce deployment does not cover:
· "Install to GAC"(GAC is another system directory)
· "Write to Registry"
· "Install for All Users" etc... While these can all be done with MSI:

Take a look to "Key Differences" between ClickOnce and MSI:
http://msdn.microsoft.com/en-us/library/142dbbz4(VS.90).aspx

So we have to code ourselves for the font installation, first: write file from embedded resource, second: add font to windows resources, third: add registry entry so the font is also available next session, finally: solve GDI+ bug, where GDI+ must be notified with this new added font, so, a scalable font resource file needs to be created, this scalable font resource file stores the name of a TrueType font file so that GDI knows where to find the file. To create a scalable font resource file, call the GDI function CreateScalableFontResource with an integer flag, the name of the font resource file to be generated, an existing TrueType font file name, and the path to the files if they do not contain a complete path.

First: Special thanks for following threads:

http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework/topic52983.aspx
http://www.daniweb.com/forums/thread231795.html
http://www.dotnetmonster.com/Uwe/Forum.aspx/winform/18215/ClickOnce-deployment-include-font

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.Drawing.Text;
using System.Windows.Forms;
namespace myNameSpace

{
class InstallFonts
{
// PInvoke to look up fonts path
[DllImport("shfolder.dll", CharSet = CharSet.Auto)]
private static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder, IntPtr hToken, int dwFlags, StringBuilder lpszPath);

private const int CSIDL_FONTS = 0x0014;
private const int MAX_PATH = 260;
private static string GetFontsPath()
{
StringBuilder sb = new StringBuilder(MAX_PATH);
SHGetFolderPath(IntPtr.Zero, CSIDL_FONTS, IntPtr.Zero, 0, sb);
return sb.ToString();
}

// PInvoke to 'register' fonts and broadcast addition

[DllImport("gdi32.dll")]
private static extern int AddFontResource(string lpszFilename);

[DllImport("gdi32", EntryPoint = "RemoveFontResource")]
private static extern bool RemoveFontResourceW(string lpFileName);

[DllImport("gdi32.dll")]
private static extern int CreateScalableFontResource(uint fdwHidden, string lpszFontRes, string lpszFontFile, string lpszCurrentPath);

private static IntPtr HWND_BROADCAST = new IntPtr(0xffff);
private const uint WM_FONTCHANGE = 0x001D;

[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

public static void InstallFont()
{

string fontsPath = GetFontsPath();
string ttfFile9 = System.IO.Path.Combine(fontsPath, "V100009_.TTF"); ;
string fotFile9 = System.IO.Path.Combine(fontsPath, "V100009_.FOT"); ;

int ret;
if (!System.IO.File.Exists(ttfFile9))
{
//Write file from embedded resource
System.IO.File.WriteAllBytes(ttfFile9, MyFonts.V100009_);
//Allow GDI+ to be notified and determines the new fonts
//to install a TrueType font, a scalable font resource file needs to be
//created. This scalable font resource file stores the name of a TrueType
//font file so that GDI knows where to find the file. To create a scalable
//font resource file, call the GDI function CreateScalableFontResource with
//an integer flag, the name of the font resource file to be generated, an
//existing TrueType font file name, and the path to the files if they do not
//contain a complete path.
ret = CreateScalableFontResource(0, fotFile9, ttfFile9, String.Empty);
//Add font resource
ret = AddFontResource(fotFile9);
//Add registry entry so the font is also available next session
Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", "C39HrP36DlTt (TrueType)", "V100009_.TTF", RegistryValueKind.String);

//Broadcast to let all top-level windows know about change
ret = SendMessage(HWND_BROADCAST, WM_FONTCHANGE, new IntPtr(0), new IntPtr(0));
//Work around to use font after installing without restarting the installing application
//It is GDI+ bug not .NET bug,
PrivateFontCollection oPFC9 = new PrivateFontCollection();
oPFC9.AddFontFile(ttfFile9);
}
}
}
}