Current filter:
                                You should refresh the page.
                                Support Center
                                0
                                  • I need to make a provider decision on the Web Service end. I'd prefer to use remoting, but the majority of my clients are running the Compact Framework, and so remoting isn't an option. Is it possible to transfer XPO data via an XML WebService?

                                1 Solution

                                Creation Date Rating Importance Sort by
                                0

                                ========================
                                This article is now obsolete. Now XPO provides built-in classes for IDataStore services. Refer to the Transferring Data via WCF Services article.
                                ========================

                                Yes, it's possible to make XPO pass its data and SQL queries through a Web service. We advise that you download and test the sample project attached to this article.

                                Web Service

                                The Application_Start procedure in Global.asax creates a connection provider for a particular database - this is an MS Access database in our example.

                                [C#]
                                void Application_Start(object sender, EventArgs e) { Application["provider"] = DevExpress.Xpo.XpoDefault.GetConnectionProvider( DevExpress.Xpo.DB.AccessConnectionProvider.GetConnectionString(Server.MapPath("App_Data\\ContactManagement.mdb")), DevExpress.Xpo.DB.AutoCreateOption.SchemaAlreadyExists); }
                                [VB.NET]
                                Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) Dim conn As String = DevExpress.Xpo.DB.AccessConnectionProvider.GetConnectionString(Server.MapPath("App_Data\ContactManagement.mdb")) Application("provider") = DevExpress.Xpo.XpoDefault.GetConnectionProvider(conn, DevExpress.Xpo.DB.AutoCreateOption.SchemaAlreadyExists) End Sub

                                The MyXpoService Web service is implemented in App_Code\MyXpoService.cs. It's a WebService descendant. It must expose four methods: SelectData, ModifyData, UpdateSchema and GetAutoCreateOption.

                                [C#]
                                [WebService(Namespace = WebServiceAttribute.DefaultNamespace)] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class MyXpoService : System.Web.Services.WebService { public MyXpoService() { } [WebMethod] public ModificationResult ModifyData(params ModificationStatement[] dmlStatements) { IDataStore provider = (IDataStore)Application["provider"]; return provider.ModifyData(dmlStatements); } [WebMethod] public SelectedData SelectData(params SelectStatement[] selects) { IDataStore provider = (IDataStore)Application["provider"]; return provider.SelectData(selects); } [WebMethod] public UpdateSchemaResult UpdateSchema(bool dontCreateIfFirstTableNotExist, params DBTable[] tables) { // do nothing (do not allow DB schema updates via a public Web service) return UpdateSchemaResult.SchemaExists; } [WebMethod] public AutoCreateOption GetAutoCreateOption() { return AutoCreateOption.SchemaAlreadyExists; } }
                                [VB.NET]
                                <WebService(Namespace:=WebServiceAttribute.DefaultNamespace), _ WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _ Public Class MyXpoService Inherits System.Web.Services.WebService <WebMethod()> _ Public Function ModifyData(ByVal ParamArray dmlStatements As ModificationStatement()) As ModificationResult Dim provider As IDataStore = CType(Application("provider"), IDataStore) Return provider.ModifyData(dmlStatements) End Function <WebMethod()> _ Public Function SelectData(ByVal ParamArray selects As SelectStatement()) As SelectedData Dim provider As IDataStore = CType(Application("provider"), IDataStore) Return provider.SelectData(selects) End Function <WebMethod()> _ Public Function UpdateSchema(ByVal dontCreateIfFirstTableNotExist As Boolean, ByVal ParamArray tables As DBTable()) As UpdateSchemaResult ' do nothing (do not allow DB schema updates via a public Web service) Return UpdateSchemaResult.SchemaExists End Function <WebMethod()> _ Public Function GetAutoCreateOption() As AutoCreateOption Return AutoCreateOption.SchemaAlreadyExists End Function End Class

                                For security reasons, the UpdateSchema method does nothing, and GetAutoCreateOption always returns SchemaAlreadyExists. You should create a separate application, which creates and updates your database's schema.

                                Prior to you publishing your Web service, you'll need to change its Namespace parameter to a unique string. For example:

                                [C#]
                                [WebService(Namespace = "http://my-company-site.com/webservices/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class MyXpoService : System.Web.Services.WebService { public MyXpoService() { } ...
                                [VB.NET]
                                <WebService(Namespace:= "http://my-company-site.com/webservices/" ), _ WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _ Public Class MyXpoService Inherits System.Web.Services.WebService ...

                                Client Application

                                Please use the ContactManagement demo shipped with XPO to test MyXpoService. Launch ContactManagement.exe with the Web service's URL specified as a command line argument:

                                ContactManagement.exe http://localhost:2224/XpoGate/MyXpoService.asmx

                                Before you publish your Web service, you must change its namespace to a unique name. When you do so, you won't be able to use XpoDefault.GetDataLayer method any longer, because it creates a WebServiceDataStore instance with a default namespace. You should inherit the WebServiceDataStore class and decorate your descendant with WebServiceBinding attribute.

                                [C#]
                                using System.Web.Services; [WebServiceBinding(Namespace = "http://my-company-site.com/webservices/")] class MyWebDataStore : DevExpress.Xpo.WebServiceDataStore { public MyWebDataStore(string url) : base(url, DevExpress.Xpo.DB.AutoCreateOption.SchemaAlreadyExists) { } }
                                [VB.NET]
                                <WebServiceBinding(Namespace := "http://my-company-site.com/webservices/")> _ Friend Class MyWebDataStore Inherits DevExpress.Xpo.WebServiceDataStore Public Sub New(ByVal url As String) MyBase.New(url, DevExpress.Xpo.DB.AutoCreateOption.SchemaAlreadyExists) End Sub End Class

                                Here is the code to initialize the XPO Data Layer in the entry point of a client application:

                                [C#]
                                using DevExpress.Xpo; [STAThread] static void Main() { InitDAL(); Application.Run(new Form1()); } private static void InitDAL() { string serviceUrl = "http://localhost:2224/XpoGate/MyXpoService.asmx"; XpoDefault.DataLayer = new SimpleDataLayer(new MyWebDataStore(serviceUrl)); }
                                [VB.NET]
                                Imports DevExpress.Xpo <STAThread> _ Shared Sub Main() InitDAL() Application.Run(New Form1()) End Sub Private Shared Sub InitDAL() Dim serviceUrl As String = "http://localhost:2224/XpoGate/MyXpoService.asmx" XpoDefault.DataLayer = New SimpleDataLayer(New MyWebDataStore(serviceUrl)) End Sub

                                The Web service is created with AutoCreateOption equal to SchemaAlreadyExists. Hence, a client of the Web service will not be able to update the database schema. An attempt to call the UpdateSchema method will throw a SchemaCorrectionNeededException.

                                To make your Web service secure, please use IIS features. Please turn on Authenticated Access for your Web service. To enable data encryption, please utilize the SSL (https) protocol. Both these options are available from your virtual folder's Properties dialog in the Internet Information Services console.

                                See Also:
                                Creating XML Web Services in Managed Code
                                XPO Data Access Layer
                                A2709
                                HOW TO: Secure XML Web Services with Secure Socket Layer in the MSDN Library
                                Using Web Services with XPO in DX blogs
                                XPO through XML Web Services - a new detail in DX blogs
                                Announcing the XPO Publication service in DX blogs

                                If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, ASP.NET, WinForms, HTML5 or Windows 10, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Copyright © 1998-2017 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners