configure serivce.clientconfig for Silverlight project

来源:互联网 发布:sql server是数据库吗 编辑:程序博客网 时间:2024/06/08 09:10

 

In Silverlight project, when you use WCF service, there will be a ServiceReference.ClientConfig file with the service configure info, but as you know, when Silverlight projects been build, all code will be packaged in a .xap file, as well as the ServiceReference.ClientConfig file. Damned, how can I modify the service address since I want to deploy the solution in a different server? Or can I gain the runtime configuring benefit? To be more configurable, you can have two methods:

  1.  
    1. Use App.Current.Host.Source to get the Xap file Uri(http://localhost:60978/ClientBin/ReportInSl.xap) , then, combine with the relative path of the service to get the service Uri(new Uri(App.Current.Host.Source,"../../DataServices/GetReportData.svc"));
    2. Change the serviceReference.ClientConfig, to use the relative Uri in the client, shown as below:

As Is

To Be

<configuration>

    <system.serviceModel>

        <client>

            <endpoint address="http://localhost:60978/DataServices/GetReportData.svc"

                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IGetReportData"

                contract="ReportDataService.IGetReportData" name="BasicHttpBinding_IGetReportData" />

        </client>

        <bindings>

            <basicHttpBinding>

                <binding name="BasicHttpBinding_IGetReportData" maxBufferSize="2147483647"

                    maxReceivedMessageSize="2147483647">

                    <security mode="None" />

                </binding>

            </basicHttpBinding>

        </bindings>

    </system.serviceModel>

</configuration>

<configuration>

    <system.serviceModel>

        <client>

            <endpoint address="/DataServices/GetReportData.svc"

                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IGetReportData"

                contract="ReportDataService.IGetReportData" name="BasicHttpBinding_IGetReportData" />

        </client>

        <bindings>

            <basicHttpBinding>

                <binding name="BasicHttpBinding_IGetReportData" maxBufferSize="2147483647"

                    maxReceivedMessageSize="2147483647">

                    <security mode="None" />

                </binding>

            </basicHttpBinding>

        </bindings>

    </system.serviceModel>

</configuration>

原创粉丝点击