none
Getting InitParameters passed in to ClientBin .xap files

    Question

  • I'm trying to get the values I'm passing in via the "InitParameters" and I can see them coming through, but it appears they are only available after the entire page has been loaded and objects populated.  I need the values obviously on page_load and it seems the way I have things setup it's not working like that.

    Here is my Default.aspx project page object for the silverlight control to be hosted in"

     <div style="height:360px; width:300; position:absolute; top:180px; left:70%;">
            <asp:Silverlight ID="Silverlight1" runat="server" Source="~/ClientBin/slBarChartTest.xap"
                MinimumVersion="2.0.30728.0" InitParameters="DashMid=11613, AnotherVal=any" Width="100%" Height="100%"  />
        </div>


    In my silverlight project (.xap file) this is my App.xaml.cs for the passed in parms

    private void Application_Startup(object sender, StartupEventArgs e)
            {
                if (e.InitParams.Keys.Contains("DashMid"))
                {
                    int.TryParse(e.InitParams["DashMid"].ToString(), out DashMid);
    
                }
                if (e.InitParams.Keys.Contains("AnotherVal"))
                {
                    AnotherVal = e.InitParams["AnotherVal"].ToString();
            
                }
                
                this.RootVisual = new MainPage(DashMid, AnotherVal);
            }

    And my MainPage.xaml.cs

    public partial class MainPage : UserControl
        {      
            string AnotherVal = string.Empty;
            Int32 DashMid = 0;
    
            public MainPage(Int32 initDashMid, string initAnotherVal)
            {
                InitializeComponent();
    
                AnotherVal = initAnotherVal;
                DashMid = Convert.ToInt32(initDashMid);
    
                tempTxt.Content = DashMid; //show value in a label so I know it's going through
    
                this.Loaded += new RoutedEventHandler(Page_Loaded);
    
            }
    
      void Page_Loaded(object sender, RoutedEventArgs e)
            {

    if (App.Current.Resources.Contains("DashMid"))

     

    {

     

    int.TryParse(App.Current.Resources["DashMid"].ToString(), out DashMid);

     

    }

     

    if (App.Current.Resources.Contains("AnotherVal"))

     

    {

     

    AnotherVal = App.Current.Resources["AnotherVal"].ToString();

     

    }
    //Get main data here...BUT PASSED IN VALUE ISN'T IN THE DashMid????? MainDataClient client = new MainDataClient(); client.DataMemberListCompleted += new EventHandler<DataMemberListCompletedEventArgs>(client_DMembersListCompleted); client.DataMemberListAsync(DashMid); }


    Since the Application_Startup is hit first I'd imagine the passed in values should be available to the Page_Loaded event, but their not.  Hardcoding values in the startup section works or in the main_page.xaml...but when I rely on the hosting project to pass in the values it doesn't work, BUT I see the values displayed in the label (for testing purposes)????

    I'm at a huge loss here.....anyone know what the issue is????

     

    Friday, January 14, 2011 5:48 PM

Answers

  • Again and the most confusing thing is that if I run it straight from the Silverlight side if works perfectly with no errors...it's only when i export the .xap file into the asp.net project that something doesn't work right. 

    What do you mean by "when i export the .xap file into the asp.net project"?

    If you have an existing asp.NET project you want to host your Silverlight application, you should make that project as your Main Web project. You can get rid of the testing Web project which was created when you create the Silverlight project. 

    1) Add the exiting asp.NET project to your solution. Right click that project to open the Property page. On the Silverlight application tab, Add Silverlight link to point to your Silverlight project.  Now this ASP.NET project should be your main Web project. The Silverlight TestPage.html/aspx should be generated under this project.

    2) Move your service under your Silverlight Testing Web project to this asp.NET project.  The clean way to do it is Add a new Silverlight Enabled WCF service to this ASP.NET project.  Then copy the old code over to this new service file.

    3) Update your Service Reference under your Silverlight project. Change the service end point address in the ClientConfig to use relative URL: "../XXXXXX.svc"

    4) Test your Silverlight app by make the Asp.NET project as start-up project, the Silverlight testpage.html as start page.

    5) Add the following code to your Service call completed event:

    void client_DMembersListCompleted(sender, e)

    {

    if(e.Error != null)
    MessageBox.Show(e.Error.Message);
    else
    //Access e.Result
    }

    Now run your app. You should be able to debug your service as well by putting a break point at your Service function under your asp.NET project.



    Tuesday, January 18, 2011 2:25 PM
  • when deleteing and re-adding my ServiceReference it gives me two choices now as it's seeing to services at different ports the new one at http://localhost:2867/MainData, so I used that one and changed the endpoint again as it recreates that to show address="../MainData.svc". 

    Remove the old Testing Web Project from your solution. Re-add the Service Reference to make sure you use the one on your Main Web. 

    Wednesday, January 19, 2011 9:54 AM

All replies

  • You passed those two values in the MainPage's constuctor and set them in the AnoterVal/DashMid Page level variable. Then in Page_Loaded event handler all you need to do is to read from AnotherVal and DashMid variable. 

    But in your code why are you trying to read from App.Current.Resources which does not make any sense at all?



    Friday, January 14, 2011 8:20 PM
  • I was following a simple online tutorial and this was the approach (I agree, it doesn't make sense).

    I added that "App.Current.Resources" part in as a last attempt (as the tutorial had it)...I originally left that out and attempted to obtain the values at the first portion of my MainPage code (MainPage()) with no luck.  It's as if the values dont get loaded in the MainPage.cs portion until the page.unload event (if there is one).

    If I hardcode a value in the App file it works fine...If I pass a value in from the Default.aspx page it seems to not be available until everything is finished and then it's populated?? 

    Friday, January 14, 2011 10:12 PM
  • What do you mean?

    The value is available at the Application_Startup when you read them from the initParam. Then you pass it to the MainPage's constructor which is all right. It is should be available to your MainPage since then.

    public MainPage : UserControl

    {

            string AnotherVal = string.Empty;
           
    Int32 DashMid = 0;
           
    public MainPage(Int32 initDashMid, string initAnotherVal)
           
    {
               
    InitializeComponent();

               
    AnotherVal = initAnotherVal; // Here you assign this value to the Page level variable
                DashMid = initDashMid;

    }

    MainPage_Loaded(s,e)

    {  

         MainDataClient client = new MainDataClient();
        client
    .DataMemberListCompleted += new EventHandler<DataMemberListCompletedEventArgs>(client_DMembersListCompleted);
        client
    .DataMemberListAsync(DashMid);  // AnotherVal and DashMid should have the value you passed in

    }

    }

    Put a break point at Application_Startup to see what value did you get from the InitParam. Then put a break point at MainPage_Loaded to check DashMid should be the same value you passed in.



    Friday, January 14, 2011 10:39 PM
  • Hi,

    I'm trying to get the values I'm passing in via the "InitParameters

    Here is relevant article from MSDN, maybe it will give you some helps.

    http://msdn.microsoft.com/en-us/library/cc189004(v=vs.95).aspx

     

    Regards

    Tuesday, January 18, 2011 4:34 AM
  • To test I have to hardcode a value in (which works fine), but when I import the SL project in .xap form to another project I cant step through things, so I simply added in a label to see if the value I was passing was going through and it passes in fine as it displays when I run it, BUT my object isn't populating which says something is wrong.  Works with hardcoded value, but not the same passed in value!

    Attached is my query I'm using to get the data using the passed in value....does everything look fine with this?  It's the only other thing I can think of that would be causing an issue.  Specifically how I'm appeding to the sql string with the end portion "sql = sql + Convert.ToInt32(DashMid);"

    [OperationContract]
            public List<DMembers> DataMemberList(Int32 DashMid)
            {
                var connString = ConfigurationManager.ConnectionStrings["theAxv45"].ConnectionString;
                var dmList = new List<DMembers>();
                
                using (SqlConnection conn = new SqlConnection(connString))
                {
    
                    string sql = @"select dm.dmID, dm.DashID, dm.dsID, dm.dsoID from Dash_Member dm
                                        join Datasource dsm on dm.DatasourceID = dm.DatasourceID where dsm.DatasourceID = dm.DatasourceID and dm.dmID = ";// + Convert.ToString(DashMid)+;
                     sql = sql + Convert.ToInt32(DashMid);                                                 conn.Open();
    
    ..etc..


     

    Tuesday, January 18, 2011 9:58 AM
  • Do you know how to use the Debugger?

    Put a break point at each line which refers the DashMid variable, such as on the line when you are calling the Load function with this variable, then on your Service function.  Move your cursor to this variable to check value when you hit the break point.  See what is going on. 




    Tuesday, January 18, 2011 10:16 AM
  • ouch...Yes, I have debugged the Silverlight application with a "hardcoded value" in place and it works perfectly.  Hard coding the value in is the only way I know how to imitate a value being passed in for testing purposes, unless there is some way of debugging a silverlight .xap file in a .net asp application that I'm not aware of??

    In my asp.net app it is complaining however and saying there is anunhandled exception at slBarChartTest.ServiceReference1.DataMemberListCompletedEventArgs.get_Result()

    at slBarChartTest.MainPage.client_DMembersListCompleted(object sender, DataMemberListCompletedEventArgs e).

    Which is odd, why this doesn't happen when I run the Silverlight application by itself.

        void Page_Loaded(object sender, RoutedEventArgs e)
            {           
    
                InitRadChart();
                HtmlPage.RegisterScriptableObject("slChartPage", this);
                
            }
    
            private void InitRadChart()
            {
                Init2DChart();
            }
    
            private void Init2DChart()
            {
                //Get Data to populate barChart with main data
                MainDataClient client = new MainDataClient();
                client.DataMemberListCompleted += new EventHandler<DataMemberListCompletedEventArgs>(client_DMembersListCompleted);
                client.DataMemberListAsync(DashMid);
    
            } 
    
    void client_DMembersListCompleted(object sender, DataMemberListCompletedEventArgs e)
            {
                if (e.Result.Count != 0)
                {
                    string conSt1= (e.Result[0].ConStr.ToString());
                    string conSt2= (e.Result[0].BackStr.ToString());
                    string mSq = (e.Result[0].Objs.ToString());
    
                    MainDataClient client = new MainDataClient();
                    client.FinalValuesListCompleted += new EventHandler<FinalValuesListCompletedEventArgs>(client_FinalValuesListCompleted);
                    client.FinalValuesListAsync(conSt1, conSt2, mSq);
                }
    }


     

     

    Tuesday, January 18, 2011 11:08 AM
  • ouch...Yes, I have debugged the Silverlight application with a "hardcoded value" in place and it works perfectly.  Hard coding the value in is the only way I know how to imitate a value being passed in for testing purposes, unless there is some way of debugging a silverlight .xap file in a .net asp application that I'm not aware of??


    If you mean you debug your app by changing some code to use hard coded value, then run the app to see the result, that's not the right way (some times when you don't have a debugger, that might be the last resort) to debug when you can use a debugger.  And I hope that's not the way how you develop your app (from now on).

    Debugging means you use the Debugger tool that comes with the VS.  Put a break point (do you know what break point is?) at your code, then hit F5 to run your app. When your break point is hit, it will stop there so you can inspect what is going on in the code.

    See this tutorial on how to use VS Debugger:

    http://dotnetperls.com/debugging




    Tuesday, January 18, 2011 12:26 PM
  • lol, very familiar on how to debug an application and using F5 and hitting break points.  I have done this.

    I've added in a try catch block on the below code section and now I no longer receive the error on my asp.net end because it's being captured now, but I cant tell what the issue is because when I debug the silverlight application (using F5 and break points) everything works fine.  ????

    void

    client_DMembersListCompleted(object sender, DataMemberListCompletedEventArgs e)

    {

    try

    { 

    //if I try and set this value AFTER the below strings if never shows on the asp.net side...so it appears the issue is around here.  Checking the incoming values all look fine(e.result)

    tempTxt.Content = "11613";

    string conStr1 = (e.Result[0].ConnectionString.ToString());  string mainSql = (e.Result[0].ObjSQL.ToString()); MainDataClient client = new MainDataClient();

    client.FinalValuesListCompleted +=

    new EventHandler<FinalValuesListCompletedEventArgs>(client_FinalValuesListCompleted);

    client.FinalValuesListAsync(conStr1, mainSql);

    }

    catch (Exception t)

    {

    Console.WriteLine("An error occurred: '{0}'", t);

    }

    Tuesday, January 18, 2011 12:38 PM
  • I think this is more related now to my service than any values not being passed in properly as I previously thought.

    If I comment out the second call there are no errors in my asp.net project side...and if I uncomment it then it throws an error. 

    //MainDataClient client2 = new MainDataClient();
                        //client2.FinalValuesListCompleted += new EventHandler<FinalValuesListCompletedEventArgs>(client2_FinalValuesListCompleted);
                        //client2.FinalValuesListAsync();


    Again and the most confusing thing is that if I run it straight from the Silverlight side if works perfectly with no errors...it's only when i export the .xap file into the asp.net project that something doesn't work right.  Can anyone see an issue with the way I'm doing this?  (entity wont work for my situation and I cant use POCO, so this is why it looks old school, in case anyone is wondering)

     

    Here is my service:

    using System;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.ServiceModel.Activation;
    using System.Collections.Generic;
    using System.Text;
    using System.Data;
    using System.Configuration;
    using System.Data.SqlClient;
    
    namespace slBarChartTest.Web
    {
        [ServiceContract(Namespace = "")]
        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
        public class MainData
        {
            [OperationContract]
            public List<DMembers> DataMemberList(Int32 DashMid)
            {
                var connString = ConfigurationManager.ConnectionStrings["theDash45"].ConnectionString;
                var dmList = new List<DMembers>();
                        
                using (SqlConnection conn = new SqlConnection(connString))
                {
    
                     string sql = @"select * from myTable  where dsID = 11613; 
                    conn.Open();
                    using (SqlCommand cmd = new SqlCommand(sql, conn))
                    {
                        SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                        if (dr != null)
                            while (dr.Read())
                            {
                                var datamembers = new DMembers
                                {
                                    //list out all column variables from DMembers class
                                    dmID = dr.GetInt32(0),
                                    dID = dr.GetInt32(1),
                                    dsID = dr.GetInt32(2),
                                    dsoID = dr.GetInt32(3),
                                    ObjSQL = dr.GetString(4)
    //etc...
    
                                };
                                dmList.Add(datamembers);
                            }
                        return dmList;
                    }
    
                }
            }
          
    
            [OperationContract]
            public IEnumerable<Dictionary<string, object>> FinalValuesList(string mainConn, string backupConn, string mainSql)
            {
                var table = GetDataTable(mainSql, mainConn, backupConn);
    
                var columns = table.Columns.Cast<DataColumn>();
    
                return table.AsEnumerable().Select(r => columns.Select(c =>
                                     new { Column = c.ColumnName, Value = rCoffee })
                                 .ToDictionary(i => i.Column, i => i.Value != DBNull.Value ? i.Value : null));
    
            }
    
            public DataTable GetDataTable(string mainSql, string mainConn, string backupConn)
            {
                            var conn = new SqlConnection(mainConn);              var conn2 = new SqlConnection(backupConn); 
                var adapter = new SqlDataAdapter();
                adapter.SelectCommand = new SqlCommand(mainSql, conn);
    
                var table = new DataTable();
    
                conn.Open();
                try
                {
                    adapter.Fill(table);
                }
                finally
                {
                    conn.Close();
                }
    
                return table;
            }
    
            // Add more operations here and mark them with [OperationContract]
        }
    }


     

    Tuesday, January 18, 2011 2:01 PM
  • Again and the most confusing thing is that if I run it straight from the Silverlight side if works perfectly with no errors...it's only when i export the .xap file into the asp.net project that something doesn't work right. 

    What do you mean by "when i export the .xap file into the asp.net project"?

    If you have an existing asp.NET project you want to host your Silverlight application, you should make that project as your Main Web project. You can get rid of the testing Web project which was created when you create the Silverlight project. 

    1) Add the exiting asp.NET project to your solution. Right click that project to open the Property page. On the Silverlight application tab, Add Silverlight link to point to your Silverlight project.  Now this ASP.NET project should be your main Web project. The Silverlight TestPage.html/aspx should be generated under this project.

    2) Move your service under your Silverlight Testing Web project to this asp.NET project.  The clean way to do it is Add a new Silverlight Enabled WCF service to this ASP.NET project.  Then copy the old code over to this new service file.

    3) Update your Service Reference under your Silverlight project. Change the service end point address in the ClientConfig to use relative URL: "../XXXXXX.svc"

    4) Test your Silverlight app by make the Asp.NET project as start-up project, the Silverlight testpage.html as start page.

    5) Add the following code to your Service call completed event:

    void client_DMembersListCompleted(sender, e)

    {

    if(e.Error != null)
    MessageBox.Show(e.Error.Message);
    else
    //Access e.Result
    }

    Now run your app. You should be able to debug your service as well by putting a break point at your Service function under your asp.NET project.



    Tuesday, January 18, 2011 2:25 PM
  • By export I mean....I have my main asp.net application that I would like to add some silverlight functionality to.  To do this i simply add "an existing reference" by right clicking my ClientBin folder and locating the .xap file I'd like to add.

    This is how I have added two other Silverlight applications (.xap files) into my asp.net application with no problems.  Just seems to be a problem for this one. 

    html code from asp.net project -showing the other .xap files that are working in this project with no issues via ClientBin import.

        <div style="height: 400px;">
            <asp:Silverlight ID="Xaml1" runat="server" Source="~/ClientBin/SilverlightApplication1.xap"
                MinimumVersion="2.0.30728.0" Width="50%" Height="100%" OnPluginLoaded="pluginLoaded" />
        </div>
        <div style="height: 400px; position:absolute; top:0px; left:50%;">
            <asp:Silverlight ID="Xaml2" runat="server" Source="~/ClientBin/SilverlightApplication2b.xap"
                MinimumVersion="2.0.30728.0" Width="25%" Height="100%"  />
        </div>
         <div style="height:400px; width:300; position:absolute; top:140px; left:68%;">
            <asp:Silverlight ID="Silverlight1" runat="server" Source="~/ClientBin/slBarChartTest.xap"
                MinimumVersion="2.0.30728.0" InitParameters="DashMid=11613, AnotherVal=any" Width="70%" Height="100%"  />
        </div>


     

    Tuesday, January 18, 2011 2:38 PM
  • Where is your service?

    Anyway, follow the steps in my last post.

    Tuesday, January 18, 2011 2:40 PM
  • I'll take a look at your approach.  If I had say 20 SL .xap files in all that would by dynamically loaded depending on user actions how would I go about that the way you described (which sounds like it would work for one SL project, but not 20).  I'm guessing since the services for these which are built on the silverlight side would require cross domain access files for the asp.net project side which is holding the .xap files??? 

    Just trying to understand all this and it appears that my issue may simply lie in that I do not have a clientaccesspolicy/crossdomain.xml setup

     

    BTW: that error code you suggested there displays when running it saying an error occured making the request to URI 'http://localhost:3389/MainData.svc'.

    Tuesday, January 18, 2011 3:32 PM
  • (which sounds like it would work for one SL project, but not 20).

    Who said that?

    It will work for as many SL projects as you like. You can add more than than one Silverlight project to the Web Project as Silverlight link.

    The Test page will only contain one Silverlight object tag which point to the XAP you are trying to test.  But after you done testing this SL Application. You can copy this Silverlight object tag to the real page where you want it, get rid of the TestPage.






    Tuesday, January 18, 2011 3:58 PM
  • Just trying to understand all this and it appears that my issue may simply lie in that I do not have a clientaccesspolicy/crossdomain.xml setup

    My suggestion is exactly trying to avoid this cross-domain problem for you. You don't need clientaccesspolicy file. But you need to make sure to use Relative URL in the ClientConfig file and hosting your Service under your ASP.NET project.



    Tuesday, January 18, 2011 4:02 PM
  • Above I wasn't trying to suggesting you said it will only work for one....I should have added that natually more could be added.  I was just thinking to myself how easy it was to simply add just the .xap file without the need to import the whole project (which the .xap file is simply a zipped version of).  But if this way avoids the need to add in the clientaccess files I'm all for it.

    O.K, so I believe I have all your steps in place....not sure my web.config is correct however.  In my asp.net config I have the following:

     <system.serviceModel>
      <behaviors>
       <serviceBehaviors>
        <behavior name="PoC2.MainDataBehavior">
         <serviceMetadata httpGetEnabled="true" />
         <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
       </serviceBehaviors>
      </behaviors>
      <bindings>
       <customBinding>
        <binding name="customBinding0">
         <binaryMessageEncoding />
         <httpTransport />
        </binding>
       </customBinding>
      </bindings>
      <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
      <services>
       <service behaviorConfiguration="PoC2.MainDataBehavior" name="PoC2.MainData">
        <endpoint address="http://localhost:3389/MainData.svc" binding="customBinding" bindingConfiguration="customBinding0"
         contract="PoC2.MainData" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
       </service>
      </services>
     </system.serviceModel>


    I'm still receiving the error saying I'm attempting to connect to URI http://localhost:3389/MainData.svc and this could be a cross site issue, etc...

    Tuesday, January 18, 2011 4:25 PM
  • I'm still receiving the error saying I'm attempting to connect to URI http://localhost:3389/MainData.svc and this could be a cross site issue, etc...

    Did you change the service endpoint address in your serviceReferences.ClientConfig file under the Silverlight project?

    If you still trying to connect with that URL, you didn't change it to use RelativeURL as I said multiple times already.


    Tuesday, January 18, 2011 4:30 PM
  • sorry, yes this has been changed...I must not have built the entire application or something.  I re-ran and now get the "remote server returned an error: not found"

    ServiceReferences.ClientConfig

    <endpoint address="../MainData.svc" binding="customBinding"
                    bindingConfiguration="CustomBinding_MainData" contract="ServiceReference1.MainData"
                    name="CustomBinding_MainData" />


     

    Tuesday, January 18, 2011 4:55 PM
  • Is the MainData.scv under your main web project?

    O.K, so I believe I have all your steps in place....not sure my web.config is correct however.  In my asp.net config I have the following:

    What is asp.net config? Do you mean web.config? If yes, make sure to set the address="" in the Service end point tag:

     <endpoint address="http://localhost:3389/MainData.svc" binding="customBinding" bindingConfiguration="customBinding0"/>

    To: 

      <endpoint address=""  binding="customBinding" bindingConfiguration="customBinding0"/>




    Tuesday, January 18, 2011 5:32 PM
  • Yep, the DMembers.cs class I added to the web project (hope that's right) and the MainData.svc as well.  I removed that address in my web.config (not sure why I even did that)...but yes that is gone and same result.

    <configuration>
        <system.serviceModel>
            <bindings>
                <customBinding>
                    <binding name="CustomBinding_MainData">
                        <binaryMessageEncoding />
                        <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
                    </binding>
                </customBinding>
            </bindings>
            <client>
              <endpoint address="../MainData.svc" binding="customBinding"
                    bindingConfiguration="CustomBinding_MainData" contract="ServiceReference1.MainData"
                    name="CustomBinding_MainData" />
                <!--<endpoint address="http://localhost:3381/MainData.svc" binding="customBinding"
                    bindingConfiguration="CustomBinding_MainData" contract="ServiceReference1.MainData"
                    name="CustomBinding_MainData" />-->
            </client>
        </system.serviceModel>
    </configuration>


     

    <system.serviceModel>
      <behaviors>
       <serviceBehaviors>
        <behavior name="PoC2.MainDataBehavior">
         <serviceMetadata httpGetEnabled="true" />
         <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
       </serviceBehaviors>
      </behaviors>
      <bindings>
       <customBinding>
        <binding name="customBinding0">
         <binaryMessageEncoding />
         <httpTransport />
        </binding>
       </customBinding>
      </bindings>
      <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
      <services>
       <service behaviorConfiguration="PoC2.MainDataBehavior" name="PoC2.MainData">
        <endpoint address="" binding="customBinding" bindingConfiguration="customBinding0"
         contract="PoC2.MainData" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
       </service>
      </services>
     </system.serviceModel>


     

    Tuesday, January 18, 2011 5:41 PM
  • Test your Service first by right clicking MainData.svc file, select "Browse with", select a browser, click Browse. Do you see your service?


    Tuesday, January 18, 2011 5:58 PM
  • Yep, this is working.  I had to drop the .Web extension of the namespace for it to work as such(

    namespace

    PoC2)  versus PoC2.Web like it is on the silverlight side as 

    namespace

    slBarChartTest.Web

    Tuesday, January 18, 2011 6:14 PM
  •  

    I had to drop the .Web extension of the namespace for it to work as such

    What do you mean by this? Drop the .Web extension from where?

    Tuesday, January 18, 2011 7:31 PM
  • when you mentioned copying over the service "The clean way to do it is Add a new Silverlight Enabled WCF service to this ASP.NET project.  Then copy the old code over to this new service file" I created a new one which then referenced the name of the asp.net app via the namespace because it was created there and dropped in all of the copied in code, except for that line.  The namespace line. 

    The service in Silverlight has .Web in the namespace and the one created in the asp.net app does not.  If I add it in the service does not work.  If I copy the exact code over from the silverlight webservice (including the namespace) the service does not work.  So since I created the service in the asp.net side I natually assumed that the namespace should be the same as the project name....in the case namespace PoC2 and not namespace slBarChartTest.Web

    Tuesday, January 18, 2011 7:43 PM
  • OK, now your service is working, try to delete your old service reference from your Silverlight project, then add it back.

    Tuesday, January 18, 2011 8:05 PM
  • Still no luck...when deleteing and re-adding my ServiceReference it gives me two choices now as it's seeing to services at different ports the new one at http://localhost:2867/MainData, so I used that one and changed the endpoint again as it recreates that to show address="../MainData.svc".  I left it as the full path as well with no luck http://localhost:2867/MainData.svc and server error not found.  For good measure I deleted this one and used the other "original" service again and tried both things above and "server error not found" still?

    Wednesday, January 19, 2011 9:30 AM
  • when deleteing and re-adding my ServiceReference it gives me two choices now as it's seeing to services at different ports the new one at http://localhost:2867/MainData, so I used that one and changed the endpoint again as it recreates that to show address="../MainData.svc". 

    Remove the old Testing Web Project from your solution. Re-add the Service Reference to make sure you use the one on your Main Web. 

    Wednesday, January 19, 2011 9:54 AM
  • Same result...remote server not found and only one service reference is available now.  The endpoint binding is still ../MainData.svc and I checked in the browser that the service was working with both the relative uri above and the full path (tried both ways again as well).

    Wednesday, January 19, 2011 10:08 AM
  • Try this:

    Add a simple function such as public void DoWork(){} in your Service. Compile and Update your Service Reference. Change your Silverlight code to call this simple function see if you can connect. 



    Wednesday, January 19, 2011 10:29 AM
  • O.K, so the drum roll.......it works!  When I dropped the old web project there was a reference I needed so I plugged it into the asp.net web.config and all fixed.

    I appreciate all your help with this sladapter I know this one was probably a real pain, I'm sure others will find this thread filled with steps and knowledge to be very useful.

    I have a few parting questions:

    A). Is there some link you learned to do things this way out there (adding a silverlight project to an existing .net application or vice versa in these steps) as I dont recall ever seeing one?

    B). All the examples i've come across all use the embedded object tag in an asp.net apps html page to host the silverlight object by importing the associated .xap file into the asp.net ClientBin folder and make it look like a piece of cake...because it is (assuming there are no crossdomain issues).  As it seems this is where I was stuck at when doing things this way, did I simply need to place a crossdomainaccesspolicy.xml file somewhere (as it's all local wwwroot/inetpub isn't the location, so I'm not sure where and like others I started dropping it in all kinds of places with no luck)?

    C). My original goal was to load up the .xap files (about 20+) into my asp.net clientbin folder and then dynamically inject the object tags into the html page as needed to utilize the .xap files on an as needed basis.  This was until the "Server Not Found" issue.  The way you've shown me seems to suggest I'll have to add in the 20+ Silverlight projects and  recreate all their associated services in the hosting asp.net project section....does this sound accurate?

    I guess it just appears cleaner the other way, but with the crossdomain issue (correct me if I'm wrong there) as all you see is the .xap file and not the whole project....but with your way it resolves this issue.

    Again sorry this post/issue was such a dauting task, but you've helped me tremendously.

    Wednesday, January 19, 2011 11:49 AM
  • A). Is there some link you learned to do things this way out there (adding a silverlight project to an existing .net application or vice versa in these steps) as I dont recall ever seeing one?

    I have been playing with Silverlight for 3 years. If you search through the forum (well, the search engine on this forum is really inadequate, it seldom gives me what I want), you could find a lot of my old posts mentioned this. I don't know if there is one documentation talking about this. But my posts are mainly from my own experiences playing with the product.

    B). All the examples i've come across all use the embedded object tag in an asp.net apps html page to host the silverlight object by importing the associated .xap file into the asp.net ClientBin folder and make it look like a piece of cake...because it is (assuming there are no crossdomain issues).  As it seems this is where I was stuck at when doing things this way, did I simply need to place a crossdomainaccesspolicy.xml file somewhere (as it's all local wwwroot/inetpub isn't the location, so I'm not sure where and like others I started dropping it in all kinds of places with no luck)?

    Once you understand what adding Silverlight link is doing, you certainly can do whatever you want manually.  There is nothing magical about anything once you understand the principal underneath it.

    The main thing is you need to make the service as Self hosted service to avoid all the cross-domain issues.  It's better to move the service to your final Web project as early as possible.  So make your final web project as the Main Web project while developing should avoid all the issues down the road. 

    C). My original goal was to load up the .xap files (about 20+) into my asp.net clientbin folder and then dynamically inject the object tags into the html page as needed to utilize the .xap files on an as needed basis.  This was until the "Server Not Found" issue.  The way you've shown me seems to suggest I'll have to add in the 20+ Silverlight projects and  recreate all their associated services in the hosting asp.net project section....does this sound accurate?

    No matter how may xap files you have, the service should all be under this Main Web. When you add a new Silverlight application project to the solution, VS will ask if you want to create a new Web project or use an existing one. You should just point to this Main Web Project as the Web project for your new SL project.











    Wednesday, January 19, 2011 12:29 PM
  • Hi Sladapter,

        I added new Silver light enabled WCF service to my web application but I am trying to add that service reference to my silverlight application its giving bellow error.Both the apllications are in the same solution only

    The HTML document does not contain Web service discovery information.
    Metadata contains a reference that cannot be resolved: 'http://localhost:81/Test/WebService.svc'.
    The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: '
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>SmartMPM | Login</title>
    <script type="text/javascript" src="js/jquery-1.4.2.js"></script>    
    <script type="text/javascript" src="js/sifr-titles.js"></script> 
    <script type="text/javascript" src="js/jScrollPane.js"></script>
    <script type="text/javascript" src="js/jquery.mousewheel.js"></script>
    <link type="text/css" href="css/sifr.css" rel="Stylesheet" />
    <style type="text/css">
       
    /* Jquery Plugin scrollbar CSS */
    .jScrollPaneContainer {position: relative;overflow: hidden;z-index: 1;outline:none;-moz-outline-style: none;}
    .jScrollPaneTrack {position: absolute;cursor: pointer;right: 0;top: 0;height: 100%;background: #E7E7E7;}
    .jScrollPaneDrag {position: absolute;background: #D0D0D0;cursor: pointer;overflow: hidden;}
    .jScrollPaneDragTop {posi'.
    If the service is defined in the current solution, try building the solution and adding the service reference again.

    Plz help me.

    Thankyou.

     

     

     

    Tuesday, May 10, 2011 8:34 AM
  • Test your WCF service first by right clicking the .svc file and selecting "View in Browser".  Do you see any error message in the browser?


    Tuesday, May 10, 2011 5:56 PM
  • Thanks for replying,

    I tested it its not giving any error. But the problem is I added the service to my web application for that application I have forms authentication thats why its giving error. for that I wrote bellow mentioned code in my web.config its solved. I added the reference to my silverlight application but the problem is I didnt get tht reference into my MainPage.xaml in my silverlight application.

      

    <location path="MyWebService.svc">
        <system.web>
          <authorization>
            <allow users="?"/>
          </authorization>
        </system.web>
      </location> 

     

      

    plz help me.

    Thankyou

     

    Wednesday, May 11, 2011 12:16 AM
  • Thats a name sapce probem I solved it thanks for supporting

    Wednesday, May 11, 2011 2:29 AM
  •  

    I added the existing silverlight application to my solution i am getting the bellow error for ListBoxDragDropTarget Control

    Could not load file or assembly 'System.Reactive, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1b331ac6720247d9' or one of its dependencies. The system cannot find the file specified.

    But the same code is exicuting in my sample application.

    I remove the Dll's and again added to my application, again am getting same problem. bellow mentioned the dll's

    System.Windows.Controls 

    System.Windows.Controls.Toolkit 

    plz help me

    Thankyou.

     

     

     

    Wednesday, May 11, 2011 7:20 AM