Windows Store application calls SharePoint service

Source: Internet
Author: User

I have no experience in developing SharePoint before. Recently I made a small project for Windows Store and SharePoint service. Thanks to my friends, I would like to sum up my experience here for your reference.

First, each page or website of shearpoint has its own powerful WebService or WCF. You only need to add/_ Vti_bin/lists. asmx

An important issue here is that Windows Store applications automatically generate referencesCodeWill generate some errorsHttp: // ******/_ vti_bin/lists. asmxBut the actual address we add is:Http: // ******/sites/*******/_ vti_bin/lists. asmxSo I need to replace the wrong address with the vs replacement function in the project.

Do not forget to check the private network and Enterprise Authentication options in the appxmanifest file after the reference is completed because my project can be logged on in the Company domain using the Windows integrated authentication method.

 

In addition, I provide a method to call the service.System. servicemodel. Security. messagesecurityexceptionThis exception is caused by the user's failure to enter the domain and the user name and password verification,System. servicemodel. endpointnotfoundexceptionIs a network connection error.

The second way to obtain the content of a form is to callGetlistitemsasyncMethod.

         Private   Async Task <xelement> getdatafromservice ( String Servicename, String Username = Null , String Password = Null , String Domain = Null  ) {Spservice. listssoapclient Client = New  Spservice. listssoapclient ();  VaR Binding = (Basichttpbinding) client. endpoint. Binding); binding. Security. Mode = System. servicemodel. basichttpsecuritymode. transportcredentialonly; binding. Security. Transport. clientcredentialtype = System. servicemodel. httpclientcredentialtype. NTLM; client. clientcredentials. Windows. clientcredential = New Networkcredential (username, password, domain); getlistitemsresponse lists = Null  ;  Try  {Lists = Await Client. getlistitemsasync (servicename, String . Empty, Null , Null , "  1000  " , Null , Null  );}  Catch  (System. servicemodel. Security. messagesecurityexception e ){  Throw   New Messagesecurityexception ( "  Please check your user name and password.  "  );}  Catch  (System. servicemodel. endpointnotfoundexception e ){ Throw   New Endpointnotfoundexception ( "  Please check your Microsoft network connection and access permissions.  "  );}  Return  Lists. Body. getlistitemsresult ;} 

 

 The previous method will return an xelement, which requires manual parsing but is also very simple.

 Public   Async Task <observablecollection <dashboard> getdashboard ( String Username = Null , String Password = Null , String Domain = Null  ) {Xelement XML = Await Getdatafromservice ( "  Dashboardtable  "  , Username, password, domain );  VaR Items = XML. Elements (). Elements (). tolist (); VaR Result = From O In  Items  Select   New  Dashboard () {Department = O. Attribute ( "  Ows_department  "  ). Getstringfromxmlattribute (), attained = O. Attribute ( "  Ows_attained "  ). Getstringfromxmlattribute (), Target = O. Attribute ( "  Ows_target  "  ). Getstringfromxmlattribute (),}; observablecollection <Dashboard> List = New Observablecollection <dashboard> (Result );  Return  List ;} 

 

Actually, it corresponds to the value in each item in Sharepoint.

The usage is relatively simple here to pave the way for future students

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.