مشاركة عبر


كيفية القيام بما يلي: ربط بخدمة ويب

يوضح هذا المثال كيفية صواب ربط صواب الكائنات التي تم إرجاعها بواسطة استدعاءات أسلوب خدمة ويب.

مثال

يستخدم هذا المثال خدمة محتوى MSDN/TechNet النظام (MTPS النشر) صواب استرداد قائمة اللغات المعتمدة من قبل مستند محدد.

قبل الاتصال خدمة ويب تحتاج صواب إنشاء مرجع صواب عليه. صواب إنشاء مرجع ويب صواب خدمة MTPS باستخدام Microsoft Visual Studio ، اتبع الخطوات التالية:

  1. قم بفتح مشروعك في Visual Studio.

  2. في القائمة " مشروع " انقر فوق " إضافة مرجع " .

  3. في مربع الحوار تعيين URL الى http://services.msdn.microsoft.com/contentservices/contentservice.asmx?wsdl .

  4. اضغط الانتقال ثم تطبيق مرجع .

بعد ذلك، استدعاء أسلوب خدمة ويب وتعيين DataContext إطار أو عنصر التحكم المناسب او الى الكائن الذي تم إرجاعه. GetContent أسلوب الخدمة MTPS يأخذ مرجع الى getContentRequest الكائن. ولهذا المثال التالي أولاً بإعداد كائن طلب:

' 1. Include the web service namespace
Imports BindtoContentService.com.microsoft.msdn.services


...


            ' 2. Set up the request object
            ' To use the MSTP web service, we need to configure and send a request
            ' In this example, we create a simple request that has the ID of the XmlReader.Read method page
            Dim request As New getContentRequest()
            request.contentIdentifier = "abhtw0f1"

            ' 3. Create the proxy
            Dim proxy As New ContentService()

            ' 4. Call the web service method and set the DataContext of the Window
            ' (GetContent returns an object of type getContentResponse)
            Me.DataContext = proxy.GetContent(request)
// 1. Include the web service namespace
using BindtoContentService.com.microsoft.msdn.services;


...


// 2. Set up the request object
// To use the MSTP web service, we need to configure and send a request
// In this example, we create a simple request that has the ID of the XmlReader.Read method page
getContentRequest request = new getContentRequest();
request.contentIdentifier = "abhtw0f1";

// 3. Create the proxy
ContentService proxy = new ContentService();

// 4. Call the web service method and set the DataContext of the Window
// (GetContent returns an object of type getContentResponse)
this.DataContext = proxy.GetContent(request);

لعرض خصائص "أداة تجميع مجمعي البيانات" وتعديلها بعد إنشائها، يمكن: في هذا المثال، DataContext لتعيين getContentResponse كائن تم إرجاعه بواسطة GetContent الأسلوب. في المثال التالي ItemsControl بربط ويعرض locale قيم availableVersionsAndLocales من getContentResponse.

<ItemsControl Grid.Column="1" Grid.Row="2" Margin="0,3,0,0"
              ItemsSource="{Binding Path=availableVersionsAndLocales}"
              DisplayMemberPath="locale"/>

للحصول على معلومات حول البنية getContentResponse راجع وثائق "الخدمة المحتوى".

راجع أيضًا:

المهام

كيفية القيام بما يلي: توفير البيانات لربط في XAML

المبادئ

نظرة عامة لربط البيانات

نظرة عامة حول مصادر الربط