Click here to Skip to main content
16,020,249 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a project with a silverlight application and pages on aspx c# the thing is I want to use session variables from my aspx to the silverlight I have my session variables fine defined on my aspx like : Session["variableroom"] = "R1";
Now I know silverlight can´t read server variables because is only client side now I read on many places a way to do that read is making a WCF service I made the service but when I test the service like this way: svcutil.exe http://localhost:50582/Service1.svc?wsdl Appears me an error:
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 4.0.30319.1]
Copyright (c) Microsoft Corporation.  All rights reserved.

Attempting to download metadata from 'http://localhost:50582/Service1.svc?wsdl
using WS-Metadata Exchange or DISCO.
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 4.0.30319.1]
Copyright (c) Microsoft Corporation.  All rights reserved.

Error: Cannot obtain Metadata from http://localhost:50582/Service1.svc?wsdl

If this is a Windows (R) Communication Foundation service to which you have ac
ss, please check that you have enabled metadata publishing at the specified ad
ess.  For help enabling metadata publishing, please refer to the MSDN document
ion at http://go.microsoft.com/fwlink/?LinkId=65455.


WS-Metadata Exchange Error
    URI: http://localhost:50582/Service1.svc?wsdl

    Metadata contains a reference that cannot be resolved: 'http://localhost:5
82/Service1.svc?wsdl'.

    The content type text/html; charset=utf-8 of the response message does not
atch the content type of the binding (application/soap+xml; charset=utf-8). If
sing a custom encoder, be sure that the IsContentTypeSupported method is imple
nted properly. The first 1024 bytes of the response were: '


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.
g/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1"><title>
        Access
</title></head>
<body>
    <form method="post" action="login.aspx?ReturnUrl=%2fService1.svc%3fwsdl&am
wsdl" id="form1">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTEyMT
MTQwNmRkAjyubgERe+wa+zu1SQa+1OzeSGPgM30g3npbpeOcj0Q=" />

<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/w
BALSpbXlDAKl1bK4CQK1qbSRCwKM54rGBigvHph/elRb3P6X4N9lNqXZ08JRWoxeHjplX0BN2OZf"

  <div>>
        Usuario:      
        <input name="txtUsername" type="text" id="txtUsername" />
        <br /><br />
        Contraseña:
        <input name="txtPassword" type="text" id="txtPassword" />
        <br /><br />
        <input type="submit" name="Button1" value="Accesar" id="Button1" />
        <br />
        <br />
 '.


HTTP GET Error
    URI: http://localhost:50582/Service1.svc?wsdl

    The HTML document does not contain Web service discovery information.

Now on my web.config I  have:

XML
<configuration>
  <configsections>
    <sectiongroup name="system.serviceModel">
      <section name="domainServices" type="System.ServiceModel.DomainServices.Hosting.DomainServicesSection, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" allowdefinition="MachineToApplication" requirepermission="false" />
    </sectiongroup>
  </configsections>

  <system.web>
    <httpmodules>
      <add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </httpmodules>
    <compilation debug="false" targetframework="4.0" />

    <rolemanager enabled="true" />

    <authentication mode="Forms">
      &lt;forms name="TestAuthCookie" loginUrl="login.aspx" timeout="30"&gt;
        <credentials passwordformat="Clear">
          <user name="testtest" password="atestm" />
          <user name="testr" password="test" />
        </credentials>
      &lt;/forms&gt;
    </authentication>
    <authorization>
      <deny users="?" />
    </authorization>

    <profile>
      <properties>
        <add name="FriendlyName" />
      </properties>
    </profile>

  </system.web>

  <system.webserver>
    <validation validateintegratedmodeconfiguration="false" />
    <modules runallmanagedmodulesforallrequests="true">
      <add name="DomainServiceModule" precondition="managedHandler">
          type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
    </add></modules>
  </system.webserver>

  <system.servicemodel>
  
    <behaviors>
      <servicebehaviors>
        <behavior name="">
          <servicemetadata httpgetenabled="true" />
          <servicedebug includeexceptiondetailinfaults="false" />
        </behavior>
      </servicebehaviors>
    </behaviors>
    <bindings>
      <custombinding>
        <binding name="WebConferencingSystem.Web.Service1.customBinding0">
          <binarymessageencoding />
          <httptransport />
        </binding>
      </custombinding>
    </bindings>
    <services>
      <service name="WebConferencingSystem.Web.Service1">
        <endpoint address="" binding="customBinding" bindingconfiguration="WebConferencingSystem.Web.Service1.customBinding0">
          contract="WebConferencingSystem.Web.Service1" /&gt;
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </endpoint></service>
    </services>
    <servicehostingenvironment aspnetcompatibilityenabled="true">
      multipleSiteBindingsEnabled="true" /&gt;
  </servicehostingenvironment></system.servicemodel>
</configuration>


Anyone know what is happening here? Or any other solution to pass session variables to my silverlight?.
Thank you
Posted
Updated 8-Jan-11 16:00pm
v2
Comments
thatraja 8-Jan-11 22:00pm    
Added code block
#realJSOP 10-Jan-11 16:06pm    
I deleted all of the answers you posted to your own question. UPATE THE ORIGINAL QUESTION - DO NOT ANSWER YOUR QUESTION BECAUSE NOBODY WILL SEE IT.

You'll probably need to change
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

to
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]

indicating that the service must run in an application domain with ASP.NET compatibility mode set to true since you are trying to access functionality from ASP.Net.

As Abhinav S points out: you also need to keep the session alive. You can do thei by issuing a call to it every few, like 10, minutes ... otherwise the stuff you stored in the session variables will just go away.

Update:
change
public object GetSessionVariable(string key)

to
public string GetSessionVariable(string key)

giving serializer some knowledge about what it supposed to serialize. SilverLight doesn't support the [Serializable] attribute, and while there are ways around this, it's best not to get into that topic at this stage.

Now build your esrvice and update the service reference in your SilverLight project.

Before you can bind to data from this service, you need to connect to the service from your SilverLight application, and retrieve the required value(s)

Regards
Espen Harlinn
 
Share this answer
 
v2
You need to keep the service project running (and point to the proper localhost port number (ie localhost:50582).
 
Share this answer
 
Comments
Sandeep Mewara 9-Jan-11 2:51am    
Comment from OP:
How can I keep my service project running? Only accesin via http on explorer? And where to put the data you said of port, because if I make view in explorer from visual studio to the service tell me service was created and all fine the problem is when you test like at the top I said.
Thank you
coerrace 10-Jan-11 16:22pm    
Look the Answer 5 I remade the code and pasted there all we really happen now.
Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900