Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > .NET ดึงข้อมูลจาก Webservice มาแสดงใน Webpage ยังไงครับ



 

.NET ดึงข้อมูลจาก Webservice มาแสดงใน Webpage ยังไงครับ

 



Topic : 041825



โพสกระทู้ ( 11 )
บทความ ( 0 )



สถานะออฟไลน์




ดึงข้อมูลจาก Webservice มาแสดงใน Webpage ยังไงครับ พอมีตัวอย่างไหมคับ



Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2010-04-22 12:22:01 By : tineebel View : 9536 Reply : 15
 

 

No. 1



โพสกระทู้ ( 3,144 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


มีครับตัวอย่าง แต่เดินมาดูที่โต๊ะผมเอง

หรือจะทำตามวิธีด้านล่างก็ได้

1.add web reference จาก url ของ web service

2.ตั้งชื่อ web service จากนั้นเราจะเห็น web service นั้นเป็น classๆ หนึ่งใน project ของเรา

3.เวลาใช้ก็เรียกใช้งาน class ผ่าน object ได้ตามปกติ






Date : 2010-04-22 12:31:01 By : tungman
 


 

No. 2



โพสกระทู้ ( 11 )
บทความ ( 0 )



สถานะออฟไลน์


บังเอิญไม่ค่อยเก่ง ASP.Net พองูๆปลาๆ อยากดูตัวอย่างที่เอาข้อมูลไป Show ใน DataView ต่างไหมคับ หรือเข้าไปดูได้ที่ไหนคับ
Date : 2010-04-22 12:39:40 By : tineebel
 

 

No. 3



โพสกระทู้ ( 3,144 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


ต้องถามก่อนว่ามีพื้นฐานขนาดไหน เคยเขียนโปรแกรมแบบ oop ไหมครับ

webservice มันก็เหมือนเราสร้าง class ขึ้นมาใช้งานธรรมดานี้แหละ

แต่เป็น class ที่ app อื่นๆ สามารถเรียกใช้งานมันได้ด้วย แค่นี้เอง

ส่วนจะเรียกใช้งานหรือจะเอาไปแสดงผลที่ไหนนั้น ก็แล้วแต่นะออกแบบครับ
Date : 2010-04-22 13:00:07 By : tungman
 


 

No. 4



โพสกระทู้ ( 11 )
บทความ ( 0 )



สถานะออฟไลน์


แค่อยากเอาข้อมูล Show ในตารางหน้า web นะครับ
Date : 2010-04-23 09:24:07 By : tineebel
 


 

No. 5



โพสกระทู้ ( 3,144 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


ถ้า add web reference ได้แล้วก็ทำเหมือนปกตินั่นแหละครับ

โปรโมชั่นสำหรับมือใหม่เลยนะ ปกติจะไม่ค่อยให้โค้ด

--------------------------------------------------------------------------

เมื่อ add web reference เสร็จแล้ว สมมุติว่าตั้งชื่อเป็น MyWebService เวลาใช้ก็ต้อง include namespace ก่อน

Code (C#)
using MyWebService; //ชื่อที่เราตั้งให้ web service นั้น


สมมุติอีกว่า namespace MyWebService ของเรามี class ชื่อ MyService ซึ่งมี method ให้ใช้ คือ public int Add(int x, int y); เวลาจะใช้เราก็ต้องเรียกใช้ผ่าน object โดยสร้างเป็น object ขึ้นมา


Code (C#)
MyService theService = new MyService(); //สร้าง object จาก class

int result = theService.Add(1, 1); //เรียกใช้ method Add จาก theService

Label Label1 = new Label();
Label1.Text = result.ToString(); //เอาค่าใน result ไปแสดงผลที่ label
Page.Form.Controls.Add(Label1); //add Label1 ลงในบน Page


เป็นไง asp.net เหมือนเขียนเว็บไหมครับ อิอิ
Date : 2010-04-23 09:44:18 By : tungman
 


 

No. 6



โพสกระทู้ ( 11 )
บทความ ( 0 )



สถานะออฟไลน์


Code ของผมที่ดึงข้อมูล ต้องปรับตรงไหนไหมคับ เพื่อเอาข้อมูลขึ้นตารางทำได้แค่ดึงข้อมูลออกมาแสดงกับกรองข้อมูล

Code (VB.NET)
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim customerPageURL As String = "http://localhost:7047/DynamicsNAV/WS/CRONUS International Ltd/Page/Customer"

        Dim customerService As New CustomerPageRef.Customer_Service()
        customerService.Url = customerPageURL
        customerService.UseDefaultCredentials = True

        Dim customer10000 As CustomerPageRef.Customer = customerService.Read("10000")
        Response.Write(vbCrLf + "Name of Customer 10000: " + customer10000.Name + "<Br>")


        Dim filter1 As New CustomerPageRef.Customer_Filter()
        Dim filter2 As New CustomerPageRef.Customer_Filter()
        Dim filters() As CustomerPageRef.Customer_Filter = New CustomerPageRef.Customer_Filter(1) {filter1, filter2}
        Dim customers() As CustomerPageRef.Customer = customerService.ReadMultiple(filters, Nothing, 0)
        For Each customer As CustomerPageRef.Customer In customers
            Response.Write("Customer Name : " & customer.Name + "<BR> ")

        Next
End Sub

Date : 2010-04-23 11:30:29 By : tineebel
 


 

No. 7



โพสกระทู้ ( 3,144 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


เวลาดูโค้ดคนอื่นที่เขียนแบบไม่เป็นมาตรฐานนี่งงจริงๆ ซึ่งผมก็รู้หรอกนะว่าคุณ add web reference ยังไง

ทำไมต้องมีป้อน url ทีหลังด้วย ผมอ่านโค้ดคุณรู้เรื่องนะ แต่ศึกษาการใช้ web service ใหม่เถอะ

ขอร้องเอาแบบที่คนธรรมดาเขาเขียนกันน่ะ มันง่ายกว่านี้ตั้งเยอะ

Code (VB.NET)
Dim customerService As New  CustomerPageRef.Customer_Service()

'CustomerPageRef = namespace
'Customer_Service() = class


จากนั้นคุณก็สร้าง pointer ให้ชี้ไปที่ข้อมูล customer อะไรก็ไม่รู้ 10000 มาไว้ใน customer10000 โดยมี type เป็น CustomerPageRef.Customer เสร็จแล้วก็เอามาแสดงผล

Code (VB.NET)
        Dim customer10000 As CustomerPageRef.Customer = customerService.Read("10000")
        Response.Write(vbCrLf + "Name of Customer 10000: " + customer10000.Name + "<Br>")


ส่วนอันล่างนี่ก็สร้าง object จาก class Customer_Filter() 2 ชุด เก็บลง array เพื่อลงไปให้ method ReadMultiple -_-" ซึ่งจะ return กลับมาเป็น customers array จากนั้นก็เอาไปวนลูปแสดงผล

Code (VB.NET)
        Dim filter1 As New CustomerPageRef.Customer_Filter()
        Dim filter2 As New CustomerPageRef.Customer_Filter()
        Dim filters() As CustomerPageRef.Customer_Filter = New CustomerPageRef.Customer_Filter(1) {filter1, filter2}
        Dim customers() As CustomerPageRef.Customer = customerService.ReadMultiple(filters, Nothing, 0)
        For Each customer As CustomerPageRef.Customer In customers
            Response.Write("Customer Name : " & customer.Name + "<BR> ")
        Next


ส่วนตารางที่ว่านี่ใช่ gridview หรือเปล่า มันมี property ชื่อ datasource อยู่

แต่คุณจะเอา customers ของคุณไปเป็น source มันไม่ได้แน่ๆ เพราะมันคงไม่รับ object แบบเฉพาะนี้

คุณเล่น return มาเป็น type customer เลยแบบนี้ gridview ไม่รู้จักหรอกครับ

ดังนั้นถ้า web service นี้คุณเป็นคนออกแบบเอง ถ้าสามารถแก้ไข

ให้มัน return ค่าเป็น type dataset datatable ก็แก้ซะ จะได้เอาไป bind ให้ gridview มันแสดงผลได้ง่ายๆ

จะใช้งานอย่างอื่นดูง่าย แค่อ้างอิงตำแหน่งให้ถูกเท่านั้น

web service มันก็ class ธรรมดาๆ นี่แหละ เพียงแต่สามารถใช้งานข้าม app ได้ จะเขียนให้ใช้ง่ายก็ได้

จะเขียนให้ยุ่งยากก็ได้ ก็แล้วแต่จะออกแบบนะ เพราะเป็นผมเขียนใหม่ไปแล้ว
Date : 2010-04-23 12:22:26 By : tungman
 


 

No. 8



โพสกระทู้ ( 3,144 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


มาสงสัยต่อ webservice มันส่ง type customer มาได้ด้วยเหรอ งงมากมาย

แค่ผมส่ง dataset ไป jsp มันยังไม่รู้จักเลย ต้องส่งเป็น type มาตรฐาน เช่น string int หรือ array แบบนี้
Date : 2010-04-23 12:39:56 By : tungman
 


 

No. 9



โพสกระทู้ ( 11 )
บทความ ( 0 )



สถานะออฟไลน์


รับทราบครับ ขอบคุณมาก แต่เรื่อง customers object นี้แปลงไปยังไงดีครับ เพื่อเอาใส่ gridview ได้ เพราะผมไม่สามารถแก้ไข object ใน Webservice ได้คับ
Date : 2010-04-23 12:43:44 By : tineebel
 


 

No. 10



โพสกระทู้ ( 3,144 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


Code (VB.NET)
Dim Dt As New System.Data.DataTable()

Dim Dc As New System.Data.DataColumn()
Dc.DataType = System.Type.GetType("System.string")
Dc.ColumnName = "Name"
Dt.Columns.Add(Dc)

For Each customer As CustomerPageRef.Customer In customers
    Dim Dr As System.Data.DataRow = Dt.NewRow()
    Dr("Name") = customer.Name
    Dt.Rows.Add(Dr)
Next

Dim GridView1 As New GridView()
GridView1.DataSource = Dt
GridView1.DataBlind()
Page.Form.Controls.Add(GridView1)

Date : 2010-04-23 13:14:41 By : tungman
 


 

No. 11



โพสกระทู้ ( 11 )
บทความ ( 0 )



สถานะออฟไลน์


ขอบคุณมากครับ
Date : 2010-04-23 15:20:47 By : tineebel
 


 

No. 12



โพสกระทู้ ( 11 )
บทความ ( 0 )



สถานะออฟไลน์


สอบถามต่อครับ

ถ้าผมอยากให้ ขอมูลที่ได้มาจาก webservice ที่บันทึกลงใน database เท่ากับจำนวน field ที่ได้มาจาก webservice ผมต้องเขียน Code ยังไงครับ
Date : 2010-05-13 11:28:07 By : tineebel
 


 

No. 13



โพสกระทู้ ( 3,144 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


Code (VB.NET)
Dim Dt As New System.Data.DataTable()

Dim Dc As New System.Data.DataColumn()
Dc.DataType = System.Type.GetType("System.string")
Dc.ColumnName = "Name"
Dt.Columns.Add(Dc)

For Each customer As CustomerPageRef.Customer In customers
    Dim Dr As System.Data.DataRow = Dt.NewRow()
    Dr("Name") = customer.Name
    Dr("Field1") = customer.Field1
    Dr("Field2") = customer.Field2
    Dr("Field3") = customer.Field3
    Dt.Rows.Add(Dr)
Next

Dim GridView1 As New GridView()
GridView1.DataSource = Dt
GridView1.DataBlind()
Page.Form.Controls.Add(GridView1)


จากนั้นก็เอา datatable ไปดัมพ์ลง database โดยใช้ dataadapter เป็นตัวกลางในการจัดการ
Date : 2010-05-13 17:13:45 By : tungman
 


 

No. 14



โพสกระทู้ ( 11 )
บทความ ( 0 )



สถานะออฟไลน์


ขอบคุณครับ
Date : 2010-05-14 09:35:38 By : tineebel
 


 

No. 15



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook



Go to : ASP.NET การสร้าง Web Service และการเรียกใช้งาน Web Service ด้วย ASP.NET แบบ Step by Step
Go to : ASP.NET and Web Service การสร้างและเรียกใช้งาน Web Service บน .NET Framework
Date : 2012-05-13 13:16:05 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : .NET ดึงข้อมูลจาก Webservice มาแสดงใน Webpage ยังไงครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่