zoukankan      html  css  js  c++  java
  • [译]在WebService如何使用XPO

    Web Service

         在Global.asax中的Application_Start程序创建了一个特定的数据库连接提供商(这是一个例子的MS Access数据库的)

      [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 ) ;
    }
     

         该MyXpoService Web服务是实现在App_Code文件\ MyXpoService.cs。 It's a WebService descendant.这是一个WebService的后裔。 It must expose four methods: SelectData , ModifyData , UpdateSchema and GetAutoCreateOption .它必须揭露四种方法:SelectData,ModifyData,UpdateSchemaGetAutoCreateOption。

     [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 ;
    }
    }

      出于安全原因,UpdateSchema方法不执行任何操作,并GetAutoCreateOption总是返回SchemaAlreadyExists。 You should create a separate application, which creates and updates your database's schema.您应该创建一个单独的应用程序,它创建和更新您的数据库的架构。

    在此之前您发布您的Web服务,你需要改变它的命名空间参数,以一个独特的字符串。 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 ( ) { }
    . . .

    客户端应用程序

    请使用ContactManagement演示XPO随测试MyXpoService。 启动ContactManagement.exe作为命令行参数中指定的Web服务的URL:

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

     在您发布您的Web服务,你必须改变它的命名空间为一个唯一的名称。当你这样做,你将无法再使用XpoDefault.GetDataLayer方法,因为它会创建一个具有默认名称空间WebServiceDataStore实例。 你应该继承WebServiceDataStore阶级属性和装饰WebServiceBinding您的后代。

     

    [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 ) {
    }
    }
     

    下面是代码以初始化一个客户端应用程序的入口点XPO数据层:

     [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 ) ) ;
    }

    Web服务是创建AutoCreateOption等于SchemaAlreadyExists。 Hence, a client of the Web service will not be able to update the database schema.因此,一个Web服务客户端将无法更新数据库模式。 An attempt to call the UpdateSchema method will throw a SchemaCorrectionNeededException .试图调用UpdateSchema方法将抛出一个SchemaCorrectionNeededException。

        为了使您的Web服务安全存储,请使用IIS功能。 请验证身份的访问打开您的Web服务。 要启用数据加密,请使用了SSL(HTTPS)的协议。.这两个选项是从你的虚拟文件夹的属性在互联网信息服务提供控制台对话框。

  • 相关阅读:
    C# Tips Written By Andrew Troelsen
    ASP.NET:性能与缓存
    New Feature In C# 2.0
    .NET Remoting中的通道注册
    通过应用程序域AppDomain加载和卸载程序集
    Some BrainTeaser in WinDev, Can you Solve them?
    ExtJs学习笔记(24)Drag/Drop拖动功能
    wap开发体会
    关于”System.ServiceModel.Activation.WebServiceHostFactory“与"<webHttp/>"以及RestFul/启用了Ajax的WCF服务
    验证码无刷新更换
  • 原文地址:https://www.cnblogs.com/tanliang/p/1717370.html
Copyright © 2011-2022 走看看