快捷搜索:  as  2018  FtCWSyGV  С˵  test  xxx  Ψһ  w3viyKQx

菲律宾葡京娱乐场:Silverlight+CSLA快速开发应用(九)来个silverlight项目先试试



办事器端逻辑 客户端逻辑 都筹备好了

现在在办理规划中添加个silverlight项目来试试调用

在办理规划"akini"中新建一个"silverlight 利用法度榜样"项目 名称叫"akini.sl"

在刚才添加的项目"akini.sl"中添加一个名为"ServiceReferences.ClientConfig"的xml文件,此中代码如下:

xml version="1.0"?>

configuration>

system.serviceModel>

bindings>

basicHttpBinding>

binding name="basicHttpBindingConfig" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">

binding>

basicHttpBinding>

bindings>

client>

endpoint address="http://localhost:1660/WcfPortal.svc" binding="basicHttpBinding"

contract="WcfPortal.IWcfPortal"

bindingConfiguration="basicHttpBindingConfig"

name="basicHttpBindingIWcfPortal" />

client>

system.serviceModel>

configuration>

此中http://localhost:1660的端口号 按照项目"akini.WcfService"来设置

查看项目"akini.WcfService"的属性 点击"web"页 选择"特定端口" 并输入端口号

再在项目"akini.WcfService"中添加名为"WcfPortal.svc"的svc文件,其代码如下:

% @ServiceHost Service="Csla.Server.Hosts.Silverlight.WcfPortal" %>

再在添加名为"clientaccesspolicy.xml"的xml文件,其代码如下:

xml version="1.0" encoding="utf-8" ?>

access-policy>

cross-domain-access>

policy>

allow-from http-request-headers="*">

domain uri="http://*"/>

domain uri="https://*" />

allow-from>

grant-to>

resource path="/" include-subpaths="true"/>

grant-to>

policy>

cross-domain-access>

access-policy>

再打开"Web.config"文件 添加如下代码 此中数据库连接 请改动

xml version="1.0"?>

configuration>

system.web>

compilation debug="true" targetFramework="4.0" />

system.web>

connectionStrings>

add name="akiniEntities_SSO" connectionString="metadata=res://*/SSO.SSO.csdl|res://*/SSO.SSO.ssdl|res://*/SSO.SSO.msl;provider=System.Data.SqlClient;provider connection string='Data Source=.\sqlexpress;Initial Catalog="D:\DOCUMENTS AND SETTING菲律宾葡京娱乐场S\XUL\MY DOCUMENTS\VISUAL STUDIO 2010\PROJECTS\AKINI\AKINI.DATA\AKINI.MDF";Integrated Security=True;MultipleActiveResultSets=True'" providerName="System.Data.EntityClient" />

add name="akiniEntities_HR" connectionString="metadata=res://*/HR.HR.csdl|res://*/HR.HR.ssdl|res://*/HR.HR.msl;provider=System.Data.SqlClient;provider connection string='Data Source=.\sqlexpress;Initial Catalog="D:\DOCUMENTS AND SETTINGS\XUL\MY DOCUMENTS\VISUAL STUDIO 2010\PROJECTS\AKINI\AKINI.DATA\AKINI.MDF";Integrat菲律宾葡京娱乐场ed Security=True;MultipleActiveResultSets=True'" providerName="System.Data.EntityClient" />

connectionStrings>

system.serviceModel>

binding菲律宾葡京娱乐场s>

basicHttpBinding>

binding name="BinaryBinding_IWcfPortal" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">

binding>

basicHttpBinding>

bindings>

services>

service name="Csla.Server.Hosts.Silverlight.WcfPortal" behaviorConfiguration="WcfPortalBehavior">

endpoint address="" binding="basicHttpBinding" contract="Csla.Server.Hosts.Silverlight.IWcfPortal"

bindingConfiguration="BinaryBinding_IWcfPortal">

identity>

dns value="localhost"/>

identity>

endpoint>

endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

service>

services>

behaviors>

serviceBehaviors>

behavior name="WcfPortalBehavior">

serviceMetadata httpGetEnabled="true"/>

serviceDebug includeExceptionDetailInFaults="true"/>

behavior>

serviceBehaviors>

behaviors>

system.serviceModel>

configuration>

现在我们在UI上添加些控件来展示数据:

打开项目"akini.sl"的"MainPage.xaml"文件,添加几个简单的空间 代码如下:

UserControl x:Class="akini.sl.MainPage"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

mc:Ignorable="d"

d:DesignHeight="300" d:DesignWidth="400">

Gri菲律宾葡京娱乐场d x:Name="LayoutRoot" Background="White">

Grid.ColumnDefinitions>

ColumnDefinition>ColumnDefinition>

ColumnDefinition>ColumnDefinition>

Grid.ColumnDefinitions>

ListBox Height="300" HorizontalAlignment="Right"Name="lstbPst" VerticalAlignment="Center"Width="150" Grid.Column="0" />

Button Content="取Pst数据" Grid.Column="1" Height="23" HorizontalAlignment="Left" Name="btnGetData" VerticalAlignment="Center" Width="75" Click="btnGetData_Click"/>

Grid>

UserControl>

别的在cs代码中添加"btnGetData_Click"事故代码,如下:

private void btnGetData_Click(object sender, RoutedEventArgs e)

{

try

{

lstbPst.Items.Clear();

sso_pstlist pstlist;

sso_pstlist.GetAll((o, ex) =>

{

if (ex.Error != null)

MessageBox.Show(ex.Error.ToString(), "Data error", MessageBoxButton.OK);

else

{

pstlist = ex.Object;

foreach (sso_pst item in pstlist)

{

lstbPst.Items.Add(item.pst);

}

}

});

}

catch (Exception ex)

{

MessageBox.Show(ex.ToString());

}

}

在办理规划改成多启动 "akini.sl"和"akini.WcfService"为启动 OK 开始运行

在调试之前 先向sso菲律宾葡京娱乐场_pst表中添加2条数据来测试

您可能还会对下面的文章感兴趣: