[WCF][Silverlight]Podłączenie do WCFa z poziomu Silverlighta

0

Siema
Siedzę nad tym już jakiś czas i nie mogę dojść, co jest nie tak, więc byłbym wdzięczny za pomoc/natchnienie.

Mam ja sobie serwis WCF, który świetnie współpracuje z aplikacją WPF. Ale chcę też napisać jeden moduł w Silverlight'cie. Pomijając już jak wkurzające to-to jest, nie mogę dojść do tego, jak się podłączyć do WCFa.

Wyczytałem, że oczywiście nie mogę skorzystać z wsHttpBinding, dlatego dołożyłem basicHttpBinding, które powinno załatwić sprawę.
Dla jasności - config z projektu WCF:

<?xml version="1.0"?>
<!--
    Note: As an alternative to hand editing this file you can use the 
    web admin tool to configure settings for your application. Use
    the Website->Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in 
    machine.config.comments usually located in 
    \Windows\Microsoft.Net\Framework\v2.x\Config 
-->
<configuration>


    <configSections>
      <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
        <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
          <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
            <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" />
            <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
            <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
            <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
          </sectionGroup>
        </sectionGroup>
      </sectionGroup>
    </configSections>  


    <appSettings/>
    <connectionStrings/>

    <system.web>
        <!--
            Set compilation debug="true" to insert debugging 
            symbols into the compiled page. Because this 
            affects performance, set this value to true only 
            during development.
        -->
        <compilation debug="true">

          <assemblies>
            <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
            <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
          </assemblies>

        </compilation>
        <!--
            The <authentication> section enables configuration 
            of the security authentication mode used by 
            ASP.NET to identify an incoming user. 
        -->
        <authentication mode="Windows" />
        <!--
            The <customErrors> section enables configuration 
            of what to do if/when an unhandled error occurs 
            during the execution of a request. Specifically, 
            it enables developers to configure html error pages 
            to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        -->


      <pages>
        <controls>
          <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        </controls>
      </pages>

      <httpHandlers>
        <remove verb="*" path="*.asmx"/>
        <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
      </httpHandlers>
      <httpModules>
        <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </httpModules>


    </system.web>

    <system.codedom>
      <compilers>
        <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4"
                  type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <providerOption name="CompilerVersion" value="v3.5"/>
          <providerOption name="WarnAsError" value="false"/>
        </compiler>
      </compilers>
    </system.codedom>

    <!--
        The system.webServer section is required for running ASP.NET AJAX under Internet
        Information Services 7.0.  It is not necessary for previous version of IIS.
    -->
    <system.webServer>
      <validation validateIntegratedModeConfiguration="false"/>
      <modules>
        <add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </modules>
      <handlers>
        <remove name="WebServiceHandlerFactory-Integrated"/>
        <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode"
             type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode"
             type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </handlers>
    </system.webServer>


  <system.serviceModel>
    <services>
      <service behaviorConfiguration="DataServer.DataServerBehavior"
        name="DataServer.DataServer">
        <clear />
        <endpoint address="http://localhost:52865/DataServer.svc" binding="basicHttpBinding"
          bindingConfiguration="" contract="DataServer.IDataServer" />
        
        <endpoint binding="wsHttpBinding" contract="DataServer.IDataServer"
          listenUriMode="Explicit">
          <identity>
            <dns value="localhost" />
            <certificateReference storeName="My" storeLocation="LocalMachine"
              x509FindType="FindBySubjectDistinguishedName" />
          </identity>
        </endpoint>
        
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"
          listenUriMode="Explicit">
          <identity>
            <certificateReference storeName="My" storeLocation="LocalMachine"
              x509FindType="FindBySubjectDistinguishedName" />
          </identity>
        </endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="DataServer.DataServerBehavior">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

Wydaje się ok, zwłaszcza że jest w całości wygenerowany w sumie.
Kompiluje się także.
Do drugiego projektu (tego silverlightowego) dodałem ServiceReference ze wskazaniem na tenże WCF, za pierwszym razem poszło. Teraz jednak, gdy daję update otrzymuję piękny komunikat błędu:
http://www.fotosik.pl/pokaz_obrazek/2314826636b4f275.html
a w warningach info:

Custom tool warning: Endpoint 'WSHttpBinding_IDataServer' at address 'http://localhost:52865/DataServer.svc' is not compatible with Silverlight 3. Skipping...

Custom tool warning: No endpoints compatible with Silverlight 3 were found. The generated client class will not be usable unless endpoint information is provided via the constructor.

I nie mogę już, nie wiem co zrobić, na necie też za bardzo nie mogę się doczytać :/

Jakby kto mnie wspomógł - będę wdzięczny.

0

Kiedyś też miałem z tym ogromne problemy.

Zajrzałem na szybko do mojego web.configa - widnieje tam też taki fragment:

<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
		<services>
      <service behaviorConfiguration="HAKGERSoft.Services.UsersBehavior" name="HAKGERSoft.Services.Users">
        <endpoint address="" binding="basicHttpBinding" contract="HAKGERSoft.Services.IUsers"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:2698/WebFramework/Services/Users.svc"/>
          </baseAddresses>
        </host>
      </service>

Tu jest akurat serwis WCF do operacji na użytkownikach (Users).

Spróbuj wstawić podobny fragment do ciebie.

Może pomoże ..

0

Dołożyłem fragment o serviceHostingEnviroment, podobnie przed klasą mam zdefiniowany atrybut

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

Jednak to dalej nie pomaga, ciągle czepia się o brak certyfikatu...
Jeśli z fragmentu:

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <services>
      <service behaviorConfiguration="DataServer.DataServerBehavior"
        name="DataServer.DataServer">
        <clear />
        <endpoint address="http://localhost:52865/DataServer.svc" binding="basicHttpBinding"
          bindingConfiguration="" contract="DataServer.IDataServer" />
        
        <endpoint binding="wsHttpBinding" contract="DataServer.IDataServer"
          listenUriMode="Explicit">
          <identity>
            <dns value="localhost" />
            <certificateReference storeName="My" storeLocation="LocalMachine"
              x509FindType="FindBySubjectDistinguishedName" />
          </identity>
        </endpoint>
        
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"
          listenUriMode="Explicit">
          <identity>
            <certificateReference storeName="My" storeLocation="LocalMachine"
              x509FindType="FindBySubjectDistinguishedName" />
          </identity>
        </endpoint>
      </service>
    </services>

wywalę: oba odwołania do certyfikatu i endpointa baseHttp to wydaje się być ok.
Jakie są konsekwencje wywalenia certyfikatów?
No i oczywiście wywalenie baseHttp nie jest mi na rękę, bo go potrzebuję, a jak go zostawiam, to komunikuje mi, że dwa endpointy, jeśli korzystają z tego samego Uri, muszą korzystać też z tego samego obiektu wiązania (bindinga jak rozumiem).
Zagubiłem się już w tym trochę, jak ustawić dwa endpointy, żeby wskazywały na ten sam serwis WCF, na ten sam interfejs (IDataServer w moim wypadku) i żeby wszystko grało?

Edit:
Uff, udało się. Problem tkwił w certyfikatach - wywalenie ich okazało się dobrym tropem, bo bez nich działa (zapewne nie tak bezpiecznie, ale póki co pal to licho, to tylko testowanie). Potem był problem z endpointami - ale to też udało się rozwiązać dodając odpowiednie adresy względne (Bogu dzięki za StackOverflow, tam już zadali chyba każde pytanie... http://stackoverflow.com/questions/1320322/wcf-wshttpbinding-and-basichttpbinding-in-same-wcf-service-application). Problem na razie więc (raczej) zażegnany, WPF dalej działa, silverlighta udało się podłączyć, więc jest dobrze.

Dzięki, Deti, za pomoc.

1 użytkowników online, w tym zalogowanych: 0, gości: 1