protected override System.Net.WebRequest GetWebRequest(Uri uri){
System.Net.WebRequest request = base.GetWebRequest (uri);
string username = "Test";
string password = "Test";
string auth = username + ":" + password;
byte[] binaryData = new Byte[auth.Length];
binaryData = Encoding.UTF8.GetBytes(auth);auth = Convert.ToBase64String(binaryData);
auth = "Basic " + auth;
request.Headers["AUTHORIZATION"] = auth;
return request;
}
ref: Yelei's Blog
Wednesday, April 30, 2008
Friday, March 7, 2008
Remote Debugging a Web Service using Eclipse and Tomcat
This is working with Tomcat 5.0.X, Eclipse 3.2, JDK 1.4.2_*
Step 1. Configure Tomcat
a) Open up the configuration GUI ("Configure Tomcat")
b) Select the Java tab
c) Into the Java Options include (substituting the correct locations)
-Xdebug
-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
-Dcatalina.home=c:\tomcat
-Djava.endorsed.dirs=c:\tomcat\common\endorsed
-Djava.io.tmpdir=c:\tomcat
NB: These are all on separate lines, with a at each EOL
d) Select the Startup tab
e) Into the Arguments section include:
jpda
start
NB: These are all on separate lines, with a at each EOL
f) Start and Stop Tomcat completely
2. Configure Eclipse
a) While in the Java perspective select "open Debug Dialog"
b) Choose "Remote Java Application" from the tree (right click/New)
c) The defaults are all that is required.
d) Click "Debug" in the bottom corner to start it now, or Close for later
3. Debugging the Application
a) Create a breakpoint in the code
b) Click on the "Debug" (if not already debugging) (*)
c) Click on the Debug Perspective (optional)
(*) If you get an error such as "Failed to connect to remote VM. Connection Refused". This normally means that Tomcat isn't started, _or_ there is already a debugging session started via jpda. Check Tomcat is running, and check the Debug perspective to make sure that it isn't running.
Step 1. Configure Tomcat
a) Open up the configuration GUI ("Configure Tomcat")
b) Select the Java tab
c) Into the Java Options include (substituting the correct locations)
-Xdebug
-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
-Dcatalina.home=c:\tomcat
-Djava.endorsed.dirs=c:\tomcat\common\endorsed
-Djava.io.tmpdir=c:\tomcat
NB: These are all on separate lines, with a
d) Select the Startup tab
e) Into the Arguments section include:
jpda
start
NB: These are all on separate lines, with a
f) Start and Stop Tomcat completely
2. Configure Eclipse
a) While in the Java perspective select "open Debug Dialog"
b) Choose "Remote Java Application" from the tree (right click/New)
c) The defaults are all that is required.
d) Click "Debug" in the bottom corner to start it now, or Close for later
3. Debugging the Application
a) Create a breakpoint in the code
b) Click on the "Debug" (if not already debugging) (*)
c) Click on the Debug Perspective (optional)
(*) If you get an error such as "Failed to connect to remote VM. Connection Refused". This normally means that Tomcat isn't started, _or_ there is already a debugging session started via jpda. Check Tomcat is running, and check the Debug perspective to make sure that it isn't running.
Friday, February 29, 2008
Coverting Date to XMLGregorianCalendar format in java
private XMLGregorianCalendar Date2XMLDate(Date d)
throws DatatypeConfigurationException {
Calendar c = new GregorianCalendar();
c.setTime(d);
int month = c.get(Calendar.MONTH)+1;
int day = c.get(Calendar.DAY_OF_MONTH);
int year = c.get(Calendar.YEAR);
DatatypeFactory df = DatatypeFactory.newInstance();
XMLGregorianCalendar x = df.newXMLGregorianCalendarDate(year, month, day, c.getTimeZone().getOffset(d.getTime())/(60*60*1000));
return x;
}
throws DatatypeConfigurationException {
Calendar c = new GregorianCalendar();
c.setTime(d);
int month = c.get(Calendar.MONTH)+1;
int day = c.get(Calendar.DAY_OF_MONTH);
int year = c.get(Calendar.YEAR);
DatatypeFactory df = DatatypeFactory.newInstance();
XMLGregorianCalendar x = df.newXMLGregorianCalendarDate(year, month, day, c.getTimeZone().getOffset(d.getTime())/(60*60*1000));
return x;
}
Friday, February 8, 2008
How to add nodes to a TreeView WebBrowser control by using Visual C# .NET

Download the IE Web Controls here and follow instructions in ReadMe.txt to install
1. Add the TreeView Control to the WebForm1.aspx.
2. Click F7 and you will be in Code View
using Microsoft.Web.UI.WebControls;
....
.....
......
TreeNode head ;
TreeNode child;
private void Button1_Click(object sender, System.EventArgs e)
{
head = new TreeNode();
head.Text = "My First Tree Node";
TreeView1.Nodes.Add(head);//Adding Nodes
child = new TreeNode();
child.Text = "My second Tree Node";
head.Nodes.Add(child); //Adding Nodes
}
It is as simple as it seems, you can display objects and XML data using this.
Useful Resources:
Converting DateTime Object from .NET to XSD
if you are trying to consume a Java Web Service in .NET simply follow the instruction in Consuming a Web Service in .NET, you might run into some issues when dealing with DateTime Object. You want to make sure that the format of DateTime being sent to the Web Service(WS) is the one it expects. The WS i was working with required the DateTime in XSD format.
You can use XmlConvert or SoapDateTime class to convert the date to a string, but the problem is the the format they return is "2007-12-14T10:37:00.0000000-05:00" and the actual XSD format is "2007-12-14T10:37:00.000-05:00". There are 4 extra zeros. So i wrote a simple method to convert .NET DateTime Object to XSD format.
public String toXSDDateFormat(DateTime d)
{
String strD = XmlConvert.ToString(d);
String d1 = strD.Substring(0,strD.LastIndexOf(".")+4);
String d2 = strD.Substring(strD.LastIndexOf("-"),strD.Length -
strD.LastIndexOf("-"));
return d1+d2;
}
Hope this helps !!
You can use XmlConvert or SoapDateTime class to convert the date to a string, but the problem is the the format they return is "2007-12-14T10:37:00.0000000-05:00" and the actual XSD format is "2007-12-14T10:37:00.000-05:00". There are 4 extra zeros. So i wrote a simple method to convert .NET DateTime Object to XSD format.
public String toXSDDateFormat(DateTime d)
{
String strD = XmlConvert.ToString(d);
String d1 = strD.Substring(0,strD.LastIndexOf(".")+4);
String d2 = strD.Substring(strD.LastIndexOf("-"),strD.Length -
strD.LastIndexOf("-"));
return d1+d2;
}
Hope this helps !!
Thursday, February 7, 2008
Consuming a Web Service in .NET
1. Get the WSDL location(http://localhost:8080/als-2.2.1/als?wsdl), make sure the XSD location in it is correct(http://localhost:8080/als-2.2.1/als?xsd=1)
2. Use wsdl.exe. In the Command Window,
C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin>wsdl http://localhost:8080/als-2.2.1/als?wsdl
If you get errors:
Microsoft (R) Web Services Description Language Utility
[Microsoft (R) .NET Framework, Version 1.1.4322.573]
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.
Error: URI formats are not supported.
If you would like more help, please type "wsdl /?".
Simply save the .wsdl and .xsd file to the local drive and run
C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin>wsdl als.wsdl
If all goes well you will see
C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin>wsdl als.wsdl
Microsoft (R) Web Services Description Language Utility
[Microsoft (R) .NET Framework, Version 1.1.4322.573]
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.
Writing file 'C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin\AL
SService.cs'.
3. Now add this file(ALSService.cs) to you current webproject and then add the Web Service to your project.
4. To refer to the the Web Service initiate an instance in WebForm1 and you can declare the DataTypes in ALSService in your Webform.
public class WebForm1 : System.Web.UI.Page
{
ALSService als = new ALSService();
..................
//calling methods
als.methodName()
...........
...........
}
Congratulations you are now ready to consume the Web Service.
Resources:
Using wsdl.exe
2. Use wsdl.exe. In the Command Window,
C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin>wsdl http://localhost:8080/als-2.2.1/als?wsdl
If you get errors:
Microsoft (R) Web Services Description Language Utility
[Microsoft (R) .NET Framework, Version 1.1.4322.573]
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.
Error: URI formats are not supported.
If you would like more help, please type "wsdl /?".
Simply save the .wsdl and .xsd file to the local drive and run
C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin>wsdl als.wsdl
If all goes well you will see
C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin>wsdl als.wsdl
Microsoft (R) Web Services Description Language Utility
[Microsoft (R) .NET Framework, Version 1.1.4322.573]
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.
Writing file 'C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin\AL
SService.cs'.
3. Now add this file(ALSService.cs) to you current webproject and then add the Web Service to your project.
4. To refer to the the Web Service initiate an instance in WebForm1 and you can declare the DataTypes in ALSService in your Webform.
public class WebForm1 : System.Web.UI.Page
{
ALSService als = new ALSService();
..................
//calling methods
als.methodName()
...........
...........
}
Congratulations you are now ready to consume the Web Service.
Resources:
Using wsdl.exe
Registering ASP.NET on IIS after installing the .NET Framework
If you install the .NET Framework on a system that has IIS already installed, IIS is automatically configured to handle requests to ASP.NET pages, and to redirect the execution to the ASP.NET runtime. However, it may happen that you installed the framework on a Windows 2000 Professional system where IIS was not already present, and just later decided to add IIS. Registering ASP.NET on IIS is not just a matter of associating the various .aspx, .asmx, .axd, .ashx and the other ASP.NET extensions to the aspnet_isapi.dll ISAPI, more has to be done to create the ASP.NET account and to set it for ASP.NET requests, register the ISAPI itself and other stuff. Doing all this manually can be a difficult operation, and requires a good understanding of many details. Fortunately there is an utility, shipped with the .NET Framework but not documented, that can take care of these configuration chores for you. The utility is aspnet_regiis.exe, it is located under %WindowsDir%\Microsoft.NET\Framework\vx.y.zzzz\ and you should call it with the -i parameter: aspnet_regiis.exe -i
Subscribe to:
Posts (Atom)