Archive

ASP.NET


How to make your Web Reference proxy URL dynamic

By 30 Nov 2005
 

Introduction

I have been asked before, how to make the URL property for a web reference to a web service in a project, configurable in a config file instead of compiled in the web reference proxy. This is most useful when you want to deploy a project with a web reference between different business environments (like between Test/QA and Production) without recompiling the project. There is a simple way to do this that requires no coding at all on the developer’s part (provided you are using Visual Studio for .NET).

Getting Started

To follow this article, first you need to have a compiled web service to reference, and a project in which you wish to add a web reference. After you have added your web reference (which creates the proxy class with references to the web service for you automatically using VS .NET), you need to set your solution view to ‘Show All’:
Solution Explorer Show All Files
This shows the Reference.cs file for the Reference.map. This is the proxy class file that VS.NET generates automatically for you when you add a web reference.
Open up this file and notice under the constructor for the proxy class that the URL is hard coded for you inside the constructor:
Sample screenshot

Changing the URL from Static to Dynamic

We are going to change the hard coded URL in the proxy class Reference.cs to a key in the web.config of the web service client project. An appSettings section will be added automatically with the current URL, and code will be placed in the Reference.cs proxy class constructor to look for the URL there. All this will be done by changing one property setting on the proxy reference.
If you look at the web reference properties (below):
Sample screenshot
you can see that there is a configuration setting called ‘URL Behavior’. This setting is by default set to Static.
Sample screenshot
To make the URL in the Reference.cs map class code behind look for the web service URL in your web.config file, we need to change this setting to Dynamic:
Sample screenshot
Doing this in VS.NET does two things for you. It changes the Reference.cs file to have the code to look for the WSDL URL in the project’s web.config file:
Sample screenshot
And it adds the URL as a key value to the projects web.config file under appSettings:
Sample screenshot
Now you can set the URL to different servers for deployment in different environments, without having to change the code. You just change the URL in your config file for your project.

http://www.codeproject.com/Articles/12317/How-to-make-your-Web-Reference-proxy-URL-dynamic


เราต้องไฟล์ (.skin ) ไว้ใน folder App_Themes เสียก่อน

จากในในไฟล์ .skin เราก็ไปสร้าง skin id เพื่่อที่จะไปเลือก css class อีกที
อันนี้ตัวอย่าง TextBox

ตัวอย่าง Dropdownlist

เวลาเอาไปใช้งานกับ control แทนที่จะใช้ CssClass เราก็มาใช้ SkinID แทนเวลาจะแก้ไข CssClass Name ก็แก้ที่ SkinID ทีเดียวจบ


<form id=”form1″ runat=”server” method=”post”>
<form id=”form1″ runat=”server” method=”get”>
Get ส่งผ่าน URL(QueryString) ซึ่งมีข้อจำกัดเรื่องความยาว แต่สามารถเพิ่มได้ถ้าไม่ได้เพิ่มมีโอกาสเจอ error ตามนี้
The length of the query string for this request exceeds the configured  maxQueryStringLength value.

เพราะว่าต้องกำหนดค่า Maximun Data Sent ใน web config
ตาม link นี้

Post ส่งผ่าน Http Body 


GET:  Default
1) Data is appended to the URL(QueryString)
2) Data is not secret.(Can be seen by anyone) 
3) It is a single call system 
4) Maximum data that can be sent is 256. 
5) Data transmission is faster 
6) This is the default method for many browsers 

POST: 
1) Data is not appended to the URL but sent as part of Http Body.
2) Data is Secret 
3) It is a two call system. 
4) There is no Limit on the amount of data.That is characters any amount of data can be sent. 
5) Data transmission is comparatively slow. 
6) No default and should be Explicitly specified.



ref http://forums.asp.net/t/1796310.aspx/1



function pageLoad(sender, args) {
        $(‘#<%=CheckBoxList1.ClientID %>’ + ‘_0’).click(function () {
            var id = “#<%=CheckBoxList1.ClientID %>_0”;
            var checkboxlistid = “#<%= CheckBoxList1.ClientID %>”;
            if ($(‘#<%=hdIsListCheckAll.ClientId %>’).val() == “True”) {

                if ($(id).attr(‘checked’) == ‘checked’) {
                    var flag = true;
                }
                else {
                    var flag = false;
                }
                $(checkboxlistid + ” input:checkbox”).each(function () {
                    $(this).attr(‘checked’, flag);
                });
            }
        });
    }

 อธิบาย code ‘#<%=CheckBoxList1.ClientID %>’ + ‘_0’
 คือ CheckBox ตัวแรกที่เมื่อเลือกแล้วจะทำการ select ทั้งหมดให้