微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Silverlight中WCF的动态部署

1.在web.config中定义
  <appSettings>
    <add key="WcfServiceAddress" value="
http://localhost:820"/>
  </appSettings>

web.config文件内容参考:

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

<!--
  有关如何配置 ASP.NET 应用程序的详细消息,请访问
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
  <appSettings>
    <add key="WcfServiceAddress" value="http://localhost:820"/>
  </appSettings>
  <connectionStrings>
    <add name="RptPath" connectionString="\\192.128.58.248\pabo$\Job\Report"/>
    <add name="DBServerIP" connectionString="192.128.58.248"/>
  </connectionStrings> 
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>

    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="false" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
</configuration>


***********************************************************************************************************
2.在调用Silverlight的aspx和html中添加
<param name="InitParams" value='WcfServiceAddress=<%= System.Configuration.ConfigurationManager.AppSettings["WcfServiceAddress"] %>' />

代码参考

    <form id="form1" runat="server" style="height:100%">
    <div id="silverlightControlHost">
        <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
    <param name="source" value="ClientBin/PA_QCReport.xap"/>
    <param name="onError" value="onSilverlightError" />
    <param name="background" value="white" />
    <param name="minRuntimeVersion" value="4.0.50826.0" />
    <param name="autoUpgrade" value="true" />
          <param name="InitParams" value='WcfServiceAddress=<%= System.Configuration.ConfigurationManager.AppSettings["WcfServiceAddress"] %>' />
    <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration:none">
      <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="获取 Microsoft Silverlight" style="border-style:none"/>
    </a>
     </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
    </form>

***********************************************************************************************************
3.在Silverlight客户端App.xaml.cs中添加

        private void Application_Startup(object sender,StartupEventArgs e)
        {
            var slServicePath = e.InitParams["WcfServiceAddress"];
            //将读取到的WCF地址保存到资源中。
            Application.Current.Resources.Add("WcfServiceAddress",slServicePath);
            this.RootVisual = new MainPage();
        }

***********************************************************************************************************
4.在Servermanger.cs统一调用处使用如下代码
注意:主要是Application.Current.Resources["WcfServiceAddress"]

        internal static wcfMain.IwcfMainClient GetPox()         {             try             {                 if (servicePicture.State == System.ServiceModel.CommunicationState.Created)                 {                     servicePicture.Endpoint.Address =                         new System.ServiceModel.EndpointAddress(Application.Current.Resources["WcfServiceAddress"] + "/wcfMain.svc");                     ((IContextChannel)servicePicture.InnerChannel).OperationTimeout = new TimeSpan(1,240);                     return servicePicture;                 }                 else                 {                     return servicePicture;                 }             }             catch (Exception ex)             {                 MessageBox.Show(ex.Message.ToString());                 return null;             }         }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐