Showing posts with label Visual Studio 2005. Show all posts
Showing posts with label Visual Studio 2005. Show all posts

Thursday, January 29, 2009

Let's Talk about .. Visual Studio 2005-Web Services Enhancements 3.0

Today I participated a mini course of Web Services Enhancements (WSE) 3.0, instructed by Dr. Gorn Tepvorachai and Mr.Suppakrit Forbes Chatchayanusorn from Standards & Methodology Team, IT Department, BOT.


Since I have to develop the web services that return some credential results, WSE 3.0 is the solution they suggested me.

The basic concept of WSE 3.0 is there is a connection between web site and web service that makes it unable to be called directly via URL.

The instruction to Declare Security and Policy by WSE 3.0

NOTE: Make sure that you already installed WSE3.0 (runtime) to your server both WebSite and Web Service and WSE3.0 (Visual Studio Developer) on your developing machine.

At WebService Side:



-Check Your Web Service comes from New Web Site->ASP.NET Web Service

-Install WSE 3.0

-Open Solution of VS2005

- Check out the project of Web Service

-Right click at the project of Web Service

-Click WSE Settings 3.0 (at the buttom)

-In General tab, check Enable the project for Web Services Enhancements

-Check Enable Microsoft Web Services Enhancements Soap Protocol Factory

-In Diasnostics tab, Check Enable Message Trace

-Click OK button

-Check your web.config, is it added section tag with microsoft.web.services3

-Deploy your Web Service


-Try to call your web service via web browser (optional)

At WebSite:

-Check your Web Site project

-Right Click at WebSite project

-Click at WSE Settings 3.0

-In General tab, check Enable the project for Web Services Enhancement

-Update your web service


-Rebuild your project


-Test that your web is still able to call your web service


- If ok, now it's a step to set the policy.


At WebService Side:

-Right click at web service project

-Click at WSE Settings 3.0

-In Policy tab, check Enable Policy

-Click Add button

-Type your Policy Name

-Click OK

-Click Next

-Do you want to secure a service or a client?, Select Secure a service application

-Choose Client Authentication Method, for me I choose Username

-Click Next

-Click Next

-Uncheck Establish Secure Session

-Click Next

-Click Select Certificate button, if any

-Click Next

-The summary message appears, click Finish

-Now you will get [yourPolycy]Cache.config file

-Open your dot vb file of Web Service

-Under WebServiceBinding tag, add Policy tag => //Policy("YourPolicyName")> _

At WebSite:

-Right click at you project

-Click at WSE Settings 3.0

-In Policy tab, enable policy

-Add Policy

-Click OK button

-Click Next button

-Select Secure a client application

-Select authentication mode, for me I use username

-Click Next button

-Enable Perform Authorization

-Add User or Add Role
Note: if you want to use the local user or local group as the role you can see the instruction at
http://natttech.blogspot.com/2009/02/lets-talk-about-windows-server-2003.html

-Uncheck the Establish Secure Session

-Click Next button

-Select Certificate, if any

-Click Finish button

-Click OK button

-Open you dot vb file that call the Web Service

-Modify it, for example, this is my old one before modification,
[VB.Net]
Dim ServiceGetResult As New MyWeb.Business.GetResult.NATTService

change to

[VB.Net]
Dim ServiceGetResult As New MyWeb.Business.GetResult.NATTService
ServiceGetResult.SetClientCredential(Of UsernameToken)(New UsernameToken("NATTusername", "NATTpassword", PasswordOption.SendHashed))
'NATTusername and NATTpassword are your username and password.
ServiceGetResult.SetPolicy("NATT Client Policy")
'NATT Client Policy is my WebSite Policy name.
hidResult.Value = ServiceGetResult.GetResultByID(txtID.Text)

At Web Service:
Because I want to check the role of user/Web Site that call the method of my web service, so I have to add the authorize function to my web service code.
-Open your dot vb file of your web service

-Add imports System.Security.Principal

-Add imports Microsoft.Web.Services3.Security.Tokens

-Add Authorization() function
[VB.Net]

Private Sub Authorization(ByVal inputRole As String)
Dim pPrincipal As IPrincipal = RequestSoapContext.Current.Credentials.UltimateReceiver.GetClientToken(Of UsernameToken)().Principal
If Not pPrincipal Is Nothing And p.IsInRole(role) Then
Return
Else
Throw New SoapException("Access denied.", New XmlQualifiedName("Authorization"))
End If
End Sub

-Add Authorization("YourRoleName") inside your method before doing anything
Note that YourRoleName is the username or role name that you specified in WSE setting.

-Deploy your web service

At WebSite:

-Update your Web Service

Now only the user or member of role group that you specified will be juct a group that can use that method of your web service.

Monday, January 26, 2009

Let's Talk about .. Visual Studio 2005-Bind DropDownList when another DropDownList changed in Repeater

P'Beer teached me last week about how to create the drop down list B that will be binded only when drop down list A's index is changed, for the case that A and B are drop down lists in the repeater.

The Instruction to Bind DropDownList when another DropDownList changed in Repeater

-add these tags for AJAX Update Panel

[HTML]
//asp:ScriptManager ID="ScriptManager1" runat="server">
/ /asp:ScriptManager>
//asp:UpdatePanel ID="UpdatePanel1" runat="server">
"

[..your table/tr/td..]

// /ContentTemplate>
// /asp:UpdatePanel>

-Add drop down list tags

[HTML]
Drop Down List A
Drop Down List B

-In the code behind, in Sub of Repeater_ItemDataBound, bind the drop down list A by adding the following lines.

[VB.Net]
If e.Item.DataItem.A_Code <> "" Or e.Item.DataItem.A_Code IsNot Nothing Then

ddlA.SelectedValue = e.Item.DataItem.A_Code

Else
'Bind DropDownList A
ddlA.DataTextField = "Ar_Name"
ddlA.DataValueField = "A_Code"
ddlA.DataSource = (New [YourNameSpace].[YourEntity].[ABus]).GetAll_ListA()
ddlA.DataBind()
ddlA.Items.Insert(0, "") 'if you don't wanna show the first choice.

End If

-Add the event for drop down list A's seelcted index changed.

[VB.Net]
#Region " DropDown Event "
Public Sub ddlA_SelectedIndexChanged(ByVal Sender As Object, ByVal e As System.EventArgs)
Dim x As String = CType(Sender, DropDownList).ClientID


For i As Integer = 0 To Me.repMain.Items.Count - 1


Dim ddlA As DropDownList = Me.repMain.Items(i).FindControl("ddlA")
If ddlA.ClientID = x Then
Dim ddlB As DropDownList = Me.repMain.Items(i).FindControl("ddlB")
'Bind DropDownList B
ddlB.DataTextField = "B_Name"
ddlB.DataValueField = "B_Code"
ddlB.DataSource = (New [YourNameSapce].[YourEntity].[YourBus]).Get_List_B_By_A_Code(ddlA.SelectedValue)
ddlB.DataBind()
End If
Next
End Sub

#End Region

Saturday, January 10, 2009

Let's Talk about .. Visual Studio 2005-Change XML Node to DataSet

Yesterday, P'Tarn guided me how to change the XML Node to DataSet. Anyway, this way is for only the case of fixed node(s).

[VB.Net]
Dim retXmlNode As XmlNode
retXmlNode = objOutInfo.WebServiceGetInfo(InputData)
Dim retDataSet As New DataSet()
row = retTab.NewRow()
'Check that node1 for row1 is exist.
If Not (retXmlNode.SelectSingleNode("/EntityName/NodeName1") Is Nothing) Then
row("RowNameOfDataSet1") = retXmlNode.SelectSingleNode("/EntityName/NodeName1").InnerXml
End If
'Check that node2 for row2 is exist.
If Not (retXmlNode.SelectSingleNode("/EntityName/NodeName2") Is Nothing) Then
row("RowNameOfDataSet2") = retXmlNode.SelectSingleNode("/EntityName/NodeName2").InnerXml
End If
retTab.Rows.Add(row)
retDataSet.Tables.Add(retTab)
'Now you can do .. return retDataSet

Wednesday, October 8, 2008

Let's Talk about .. Visual Studio 2005-Reporting Services: Show 0.00 format

P'Kaew told me how my report in reporting services shows the format number of 0.00 (decimal point)

The instruction to show 0.00
-Right Click at the cell

-Click Properties
-In Format tab, set Format code: N

Monday, September 22, 2008

Let's Talk about .. Visual Stuido 2005-Error The timeout period elapsed prior to obtaining a connection from the pool

“Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached. “

P'Beer told me that this problem is normally the result of our forgotten coding. We usually use SQLHelper to connect to the database. Inside SQLHelper, there are many methods. We often use ExecuteReader and forget to close the connection. This method doesn't automatically close the connection, because it returns object as SqlDataReader which has to open the connection while it's reading. Thus we have to close by ourselves, otherwise, the connections will stuck inside the pool til max pool size. In fact, dot net provides a garbage collector to collect the unused connections, however, we may have to wait for an hour. Therefore, the best way to do is closing connection everytime we finish execute reading.

[VB.Net]
Dim dr as SqlDataReader = SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure, ”StroreProcedureName”, SqlParameter())
If dr.Read() Then
‘Do something
End If

dr.close()


As you see, we don't close the connection directly, but SqlDataReader instead since by colsing SqlDataReader, it closes the connection automatically.

Special Thanks to P'Beer Adisorn for this knowledge.

Monday, July 21, 2008

Let's Talk about .. Visual Stuido 2005-Open new window

I found one of the methods to open new windows (redirect to new page) from http://forums.asp.net/t/1161626.aspx
This is how to redirect to new page.

response.write("");

Friday, July 4, 2008

Let's Talk about .. Visual Studio 2005-Show Currency Format

I found on this website http://msconline.maconstate.edu/tutorials/ASPNET2/ASPNET07/aspnet07-01.aspx about how to show a text string with the format of the number (show comma symbol every 3 positions) and currency (show the currency symbol and comma symbol every 3 positions). In that website, there are two ways to show.

[VB.Net]
NumberResult.Text = String.Format("{0:N}", 111.11)
CurrencyResult.Text = String.Format("{0:C}", 222.22)

,and the second method..

[VB.net]
Dim Value As Decimal = 3333.33
NumberResult.Text = String.Format("{0:#,#.###}", Value)

CurrencyResult.Text = String.Format("{0:$ #,#.##}", Value)

Wednesday, July 2, 2008

Let's Talk about .. Visual Stuido 2005-Currency format in Grid view

      Since I use a grid view to show my data, it shows the numeric data without comma and currency symbols. Thus, I searched the method and found that this website provides the solution to me http://forums.msdn.microsoft.com/ja-JP/vbgeneral/thread/88d1abd8-9a37-4f55-ac4d-52a82e14c46f/

    The solution is adding HtmlEncode="False" and DataFormatString="{0:c} in to the code.

    For example,


    Wednesday, June 4, 2008

    Let's Talk about .. Visual Stuido 2005-Features

    Today, P'Beer, the outsource at my office teached me about what the important features of Visual Studio 2005 over Visual Studio 2003. He said that there are three vital features:
    1. AJAX (Asynchnous JavaScript and XML), while Visual Studio 2003 retrieve the data via the XMLHttpRequest object.
    2. Master Page/Detail Concept.
    3. Theme/Skin which is also included CSS.

    Friday, May 23, 2008

    Let's Talk about .. Visual Stuido 2005-Function Get DataTable or variable from SQL2005 Stored Procedure

    [VB.Net]
    Public Shared Function GetDataTableByValueAAndValueB(ByVal ValueA As String, ByVal ValueB As String) As DataTable
    Dim ds As New DataSet
    Dim SqlParam As SqlParameter() = Nothing
    addParameter(SqlParam, "@ValueA ", ValueA)
    addParameter(SqlParam, "@ValueB", ValueB)
    Helper.SqlHelper.FillDataset(ConnectionString _
    , CommandType.StoredProcedure _
    , "spPBG_Trn_TrackingList_GetDataTableByValueAAndValueB" _
    , ds _
    , dtName _
    , SqlParam)
    Return ds.Tables(dtName(0))
    End Function


    [VB.Net]
    Public Shared Function GetResultByValueAAndValueBAndValueC(ByVal ValueA As String, ByVal ValueB As String, ByVal ValueC As String) As Integer
    Dim SqlParam As SqlParameter() = Nothing
    addParameter(SqlParam, "@ValueA", ValueA)
    addParameter(SqlParam, "@ValueB", ValueB)
    addParameter(SqlParam, "@ValueC",ValueC )

    Dim dr As SqlDataReader = Helper.SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure, "GetResultByValueAAndValueBAndValueC", SqlParam)
    If dr.Read() Then
    Result = (Helper.ConvertHelper.NullToNothing(dr("Result")))
    End If

    Return Result
    End Function

    Wednesday, February 20, 2008

    Let's Talk about .. Visual Studio 2005-String Compare in VB.Net

    I am familiar with C more than VB, I just know that to compare two strings, we can use

    "[string1]".ToString() = "[string2]"

    Let's Talk about .. SQL Server 2005-mySQLConnection

    The syntax if my mySQLConnection normally is

    mySqlConnection = New SqlClient.SqlConnection("Data Source=[myServerName];Database=[myDatabaseName];Integrated Security=false;User ID=[username];Password=[password]")

    Integrated Security:
    True = No need username&password
    False = Need username&password

    Tuesday, February 5, 2008

    Let's Talk about .. VisualStudio 2005-Working with Visual SourceSelf 6.0

    By using Microsoft Visual SourceSelf, you can work as team. Many programmers can join one solution. When ProgrammerA checks out the item(s) out, other programmers cannot edit them. P'Aoi, senior system analyst at my office taught me today.

    The Instruction about how to add solution to SourceSelf's source control
    1. After creating the project or web site, click Add Solution to Source Control.
    2. Type Username, Password, and select database.
    3. Type the project name.
    4. Click Yes.
    5. Then, your solution is in Source Control. You have to check out to edit what you want.

    Thursday, October 11, 2007

    Let's Talk about .. Visual Studio 2005-Get the text from XML

    My senior office colleague, P'Tuu, told me about how I can get the text from some tags of the XML file.
    if my XML file is


    New Year Day


    First, I want "New Year Day" which is in the Day tag. I can use the following instructions to get it.

    [VB.Net]
    If Not (xdoc.SelectSingleNode("/Year/Month/Day") Is Nothing) Then
    Session("DATE") = xdoc.SelectSingleNode("/Year/Month/Day").InnerXml
    End If

    [C#.Net]
    if (xdoc.SelectSingleNode("/Year/Month/Day") != null)
    {
    DATE = xdoc.SelectSingleNode("/Year/Month/Day").InnerXml;
    }
    Second, I want "123" which is the value of the attribute Level inside Day's tag. I can use this instructions to get it.
    [VB.Net]
    If Not (xdoc.SelectSingleNode("/Year/Month/Day/@Level") Is Nothing) Then
    Session("DATE_Level") = xdoc.SelectSingleNode("/Year/Month/Day/@Level").InnerXml
    End If

    [C#.Net]
    if (xdoc.SelectSingleNode("/Year/Month/Day/@Level") != null)
    {
    DATE_Level = xdoc.SelectSingleNode("/Year/Month/Day/@Level").InnerXml;
    }

    Wednesday, October 3, 2007

    MOSS2007-Interesting Websites

    Yesterday P'Pom, Outsource from C2X Company recommended me some interesting webs/blogs about SharePoint 2007

    Let's Talk about .. Visual Studio 2005-Error Access Denied when calling Web Services

    If you got the error message "Access Denied" when you called the Web Services, I suggest this method.

    First, in Reference.cs, add the following command into the class of the Web Services that is referenced.
    [C#]
    this.PreAuthenticate = true;
    this.Credentials = System.Net.CredentialCache.DefaultCredentials;
    However, the senior colleague at my office told me that this method mostly works with VB.Net but not C#. So he recommended me to try the second method by set it as the Network Credential by assigning the username and password. (So, this one will okay when you have the username and password for the server that you call the web services)
    [C#]
    this.Credentials = new System.Net.NetworkCredential("username", "password");

    Wednesday, September 12, 2007

    Let's Talk about .. MOSS2007-Error on AllowUnsafeUpdate

    Yesterday I tried to delete the SharePoint item in the loop by using item.delete()
    Then, I got this error message,

    "Updates are currently disallowed on GET requests. To allow updates on a GET, set the 'AllowUnsafeUpdates' property on SPWeb."

    So, I searched at Google and found many people've ever got this problem. I used the solution of Robin's Sharepoint Blog. And it's worked.

    However, I got the second one,

    "Collection was modified; enumeration operation may not execute."

    Then, I searched again. I know from the MBR IT Soluctions web that because I used the foreach loop that is incremented by the SharePoint items which was deleted.

    Thursday, August 30, 2007

    Let's talk about .. MOSS2007-Enable Dubugging

    I think you may feel upset when your Web Part got error message like "Unexpected error". I found some info about how to enable debugging. However I never tried it yet. Someone told me that it's theorically fine, but not many people do it. Normally, it's practically okay when try with the computer that set server and client in 1 machine.

    This is the instruction to

    These are where I got the info from..

    http://msdn2.microsoft.com/en-us/library/e8z01xdh(VS.80).aspx

    http://blogs.msdn.com/pranab/archive/2007/07/04/how-to-implement-debug-option-in-sharepoint-application-within-vs-2005-with-complete-call-stack-instead-of-custom-error-page.aspx