none
Silverlight enabled WCF service not working with https

    Question

  • Does anyone know what I need to add to get my existing service to work with http and https?  The following is a clip of my web.config for a silverlight project of mine that is hosted within a asp.net application via the bridge.

    <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" />
            </client>
        </system.serviceModel>
    </configuration>
    <?xml version="1.0"?>
    
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    
    <configuration>
      <connectionStrings>
        <add name="someName" connectionString="server=xserver;database=mainDB;uid=rd;pwd=123456;" providerName="System.Data.SqlClient" />
      </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>
            <bindings>
                <customBinding>
                    <binding name="slRadial.Web.MainData.customBinding0">
                        <binaryMessageEncoding />
                      
                        <httpTransport />
                    </binding>
                    <binding name="slRadial.Web.MainData.customBinding1">
                   
                        <binaryMessageEncoding />
                        <httpTransport />
                    </binding>
                </customBinding>
            </bindings>
            <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
                multipleSiteBindingsEnabled="true" />
            <services>
                <service name="slRadial.Web.MainData">
                    <endpoint address="" binding="customBinding" bindingConfiguration="slRadial.Web.MainData.customBinding1"
                        contract="slRadial.Web.MainData" />
                    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
                </service>
            </services>
        </system.serviceModel>
    </configuration>
    Friday, October 14, 2011 10:18 AM

Answers

  • I created a helper class to initialize my service clients like so:

    using System.ServiceModel.Channels;
    using System.Windows;

        public class WCFServiceExtension
        {
            public WCFServiceExtension()
            {
            }

            public static WCFServiceReference.WCFServiceClient InitializeWCFServiceClient()
            {
                return new WCFServiceReference.WCFServiceClient(WCFServiceExtension.GetServiceBinding(), new System.ServiceModel.EndpointAddress(GetWebSiteRoot() + "WCFService.svc"));
            }

            public static CustomBinding GetServiceBinding()
            {
                CustomBinding binding = new CustomBinding();
                binding.Elements.Add(new BinaryMessageEncodingBindingElement());
                if (Application.Current.Host.Source.Scheme.Equals("https"))
                {
                    binding.Elements.Add(new HttpsTransportBindingElement() { MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue });
                }
                else
                {
                    binding.Elements.Add(new HttpTransportBindingElement() { MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue });
                }
                return binding;
            }

            public static string GetWebSiteRoot()
            {
                string rootURL = Application.Current.Host.Source.OriginalString;
                rootURL = rootURL.Substring(0, rootURL.LastIndexOf("ClientBin"));
                return rootURL;
            }
        }

    Then, to initialize the client:

    WCFServiceReference.WCFServiceClient wcfClient = WCFServiceExtension.InitializeWCFServiceClient();

    This assumes the service is hosted at the root of the same web site as the silverlight application.  You may need to modify the GetWebSiteRoot() according to suit your needs.

    Tuesday, October 18, 2011 8:22 AM
  • Tuesday, October 18, 2011 1:00 PM

All replies

  • Not sure if it's simply adding in the following things in bold below (note this is running locally), but with the extra few https things in place I'm receiving an error that states The HttpsGetEnabled property is set to true and HttpsGetUrl property is a relative address and no https base address is listed.  Either supply an https base address or set HttpsGetUrl to an absolute address.

    I also see some examples to this problem that use the <security mode="Transport">, but that is only with basicHttpBinding and I'm using customBindings, so I'm a bit lost here.

    WEB.config and ServiceReference

    <?xml version="1.0"?>
    
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    
    <configuration>
      <connectionStrings>
        <add.. />
      </connectionStrings>
        <system.web>
            <compilation debug="true" targetFramework="4.0" />
        </system.web>
    
        <system.serviceModel>
            <behaviors>
                <serviceBehaviors>
                    <behavior name="">
                        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                        <serviceDebug includeExceptionDetailInFaults="false" />
                    </behavior>
                </serviceBehaviors>
            </behaviors>
            <bindings>
                <customBinding>
                    <binding name="slExD.Web.ExecMainService.customBinding0">
                        <binaryMessageEncoding />
                        <httpTransport />
                    </binding>
                </customBinding>
            </bindings>
            <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
                multipleSiteBindingsEnabled="true" />
            <services>
                <service name="slExD.Web.ExecMainService">
                    <endpoint address="" binding="customBinding" bindingConfiguration="slExD.Web.ExecMainService.customBinding0"
                        contract="slExD.Web.ExecMainService" />
                    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
                </service>
            </services>
        </system.serviceModel>
    </configuration>
     
    <configuration>
        <system.serviceModel>
            <bindings>
                <customBinding>
                    <binding name="CustomBinding_ExecMainService">
                      
                        <binaryMessageEncoding />
                        <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
                      <httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />                 </binding>
                </customBinding>
            </bindings>
            <client>
                <endpoint address="https://localhost:55295/ExecMainService.svc"
                    binding="customBinding" bindingConfiguration="CustomBinding_ExecMainService"
                    contract="ServiceReference1.ExecMainService" name="CustomBinding_ExecMainService" />
            </client>
        </system.serviceModel>
    </configuration>
    Friday, October 14, 2011 11:33 AM
  • Forgot to mention I setup our IIS6 with a self-signed cert and applied it to the project/website, so that end should be covered.  Also tried to the following in my web.config to get this to work, still with no luck and when I test the service it says "Could not find a base address that matches scheme https for the endpoint with binding CustomBinding.  Registered base address schemes are [http].

    <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior name="ServerBehave">
              <serviceMetadata httpsGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <bindings>
          <customBinding>
            <binding name="slExec.Web.ExecMainService.customBinding0">
              <binaryMessageEncoding />
              <!--<httpTransport />-->
              <httpsTransport></httpsTransport>
            </binding>
          </customBinding>
        </bindings>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
            multipleSiteBindingsEnabled="true" />
        <services>
          <service name="slExec.Web.ExecMainService" behaviorConfiguration="ServerBehave">
            <endpoint address="" binding="customBinding" bindingConfiguration="slExec.Web.ExecMainService.customBinding0"
                contract="slExec.Web.ExecMainService" />
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
          </service>
        </services>
        <!--<bindings></bindings>-->
      </system.serviceModel>
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"></modules>
      </system.webServer>
    </configuration>
    

    and if I change the binding name as follows I get an error stating "The binding at system.serviceModel/bindings/customBinding does not have a configured binding named "slExec.Web.ExecMainService.customBinding0"

    <customBinding>
            <binding name="slExec.Web.ExecMainService">
              <binaryMessageEncoding />
              <!--<httpTransport />-->
              <httpsTransport></httpsTransport>
            </binding>
          </customBinding>
     
    ServiceReference:
    <configuration>
        <system.serviceModel>
            <bindings>
                <customBinding>
                    <binding name="CustomBinding_ExecMainService">
                      
                        <binaryMessageEncoding />
                        <!--<httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />-->
                      <httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
                    </binding>
                </customBinding>
            </bindings>
            <client>
                <endpoint address="https://localhost:41148/ExecMainService.svc"
                    binding="customBinding" bindingConfiguration="CustomBinding_ExecMainService"
                    contract="ServiceReference1.ExecMainService" name="CustomBinding_ExecMainService" />
            </client>
        </system.serviceModel>
    </configuration>
    Friday, October 14, 2011 2:45 PM
  • Hi,

    According to your description,I suggest you to change the clientaccesspolicy.xml:

    <?xml version="1.0" encoding="utf-8" ?>
    <access-policy>
    <cross-domain-access>
    <policy>
    <allow-from http-request-headers="*">
    <domain uri="http://*"/>
    <domain uri="https://*"/>
    </allow-from>
    <grant-to>
    <resource include-subpaths="true" path="/"/>
    </grant-to>
    </policy>
    </cross-domain-access>
    </access-policy>

    Then follow the step to enable https:

    http://www.codeproject.com/KB/WCF/7stepsWCF.aspx

    If you still have the problem, please let me know

     

    Monday, October 17, 2011 12:26 AM
  • Thanks for the response Otomii....I'll add the clientaccesspolicy to show both http and https.  The other two links though look to be using different binding methods though, so I dont think those will work with my CustomBinding unfortunately.  Going through the very limited number of tutorials using this approach I see that I may need to also have to select and "create a virtual directory" using local IIS web server (web project -> right click -> properties -> web tab -> Servers). 

    http://www.dotnetcurry.com/ShowArticle.aspx?ID=589

    This part has me a bit confused as I can do this with a test project, but in my full application I add my silverlight projects into my main .net project and dont include the web portion of them as they are using my asp.net web.config?

    Unless I'm supposed to take each silverlight project that is added to my .net project and before adding each one set up the web portion "use local iis web server" and add in the project url: https://myserverName/myPrjName (for instance).

    Is this right or is this not necessary as long as my ServiceReference for my endpoint is pointing to that location?  (<endpoint address="../myService.svc" binding="customBinding" bindingConfiguration="CustomBinding_MainData" contract="ServiceReference1.myService" name="CustomBinding_myService" />)??

     

      <system.serviceModel>
            <behaviors>
                <serviceBehaviors>
                    <behavior name="">
                        <serviceMetadata httpGetEnabled="true" />
                        <serviceDebug includeExceptionDetailInFaults="false" />
                    </behavior>
                </serviceBehaviors>
            </behaviors>
            <bindings>
                <customBinding>
                    <binding name="slHttpsTest.Web.MainData2.customBinding0">
                        <binaryMessageEncoding />
                        <httpsTransport />
                    </binding>
                </customBinding>
            </bindings>
            <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
                multipleSiteBindingsEnabled="true" />
            <services>
                <service name="slHttpsTest.Web.MainData2">
                    <endpoint address="" binding="customBinding" bindingConfiguration="slHttpsTest.Web.MainData2.customBinding0"
                        contract="slHttpsTest.Web.MainData2" />
                    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
                </service>
            </services>
        </system.serviceModel>
    </configuration>

     

    Monday, October 17, 2011 9:58 AM
  • *** Sorry if this duplicates...seems like an error occurred when I edited this post

    Thanks for the response Otomii....I'll add the clientaccesspolicy to show both http and https.  The other two links though look to be using different binding methods though, so I dont think those will work with my CustomBinding unfortunately.  Going through the very limited number of tutorials using this approach I see that I may need to also have to select and "create a virtual directory" using local IIS web server (web project -> right click -> properties -> web tab -> Servers). 

    http://www.dotnetcurry.com/ShowArticle.aspx?ID=589

    This part has me a bit confused as I can do this with a test project, but in my full application I add my silverlight projects into my main .net project and dont include the web portion of them as they are using my asp.net web.config?

    Unless I'm supposed to take each silverlight project that is added to my .net project and before adding each one set up the web portion "use local iis web server" and add in the project url: https://myserverName/myPrjName (for instance).

    Is this right or is this not necessary as long as my ServiceReference for my endpoint is pointing to that location?  (<endpoint address="..//myService.svc" binding="customBinding" bindingConfiguration="CustomBinding_myService" contract="ServiceReference1.myService" name="Custombinding_myService"/>) ??

     

      <system.serviceModel>
            <behaviors>
                <serviceBehaviors>
                    <behavior name="">
                        <serviceMetadata httpGetEnabled="true" />
                        <serviceDebug includeExceptionDetailInFaults="false" />
                    </behavior>
                </serviceBehaviors>
            </behaviors>
            <bindings>
                <customBinding>
                    <binding name="slHttpsTest.Web.MainData2.customBinding0">
                        <binaryMessageEncoding />
                        <httpsTransport />
                    </binding>
                </customBinding>
            </bindings>
            <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
                multipleSiteBindingsEnabled="true" />
            <services>
                <service name="slHttpsTest.Web.MainData2">
                    <endpoint address="" binding="customBinding" bindingConfiguration="slHttpsTest.Web.MainData2.customBinding0"
                        contract="slHttpsTest.Web.MainData2" />
                    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
                </service>
            </services>
        </system.serviceModel>
    </configuration>
    

    Monday, October 17, 2011 10:19 AM
  • Otomii the clientaccesspolicy addition worked the only quesiton I have left (issue) is the Silverlight.Web issue.  Where the only way I can get the https to work is by changing the setting in Web project -> Web Tab -> Servers -> Use Local IIS Web server and set the Project Url to "https://myWebServer/Default Web Site/MyPrjName" and create a vertual directory.  Can this be done dynamically somehow or in another way?  Deploying on a customer site would make doing this somewhat difficult and not very flexible.

    Thanks for any help here

    btw:  I tried adding a base address set to the same path as above and leaving the Web setting alone "Use Visual Studio Development Server" instead of the "Use local IIS Web Server", but no luck...saying  Could not find a base address that matches scheme https for the endpoint with binding CustomBinding...

    Monday, October 17, 2011 11:23 AM
  • I see several things missing form your web.config.  See my post here for a complete example for enabling both http and https traffic over a wcf service:

    http://social.msdn.microsoft.com/Forums/en-US/silverlightarchieve/thread/0a611684-d592-403b-bce6-0a6a605b1cee/

     

    Monday, October 17, 2011 11:58 AM
  • Hey Rjacobs....  if I browse to my service via http or https it works or right click on my service and view in browser it shows I have access.  The big issue to me is that it only works with me setting the project url path in the web tab of the web project and creating a virtual directory.  I guess me question is how do I get around doing that or making that process dynamic so that I can easily change it without having to do that to every Silverlight Project I have.  Otherwise I'll have to change this path as it stands 5 times (5 SL projects) and each time I deploy this out to a customer so that it refelcts "their" specific path.

    Monday, October 17, 2011 12:27 PM
  • trag1

    I saw you sent me a private message and I already replyed it there. Have you read it?

    Always use relative URL for your service (if you host the service under your own app) . Change the endpoint address in your ClientConfig to use the relative URL ("../YourService.svc"). This way your app will alwasy work no matter if you run it under DEV or IIS, use HTTP or HTTPS protocol. And you don't need a cross-domain policy file either in this case.

    Monday, October 17, 2011 12:42 PM
  • hi Sladapter...thx for getting back to me.  I've been trying on a simple stand alone SL project, but cant seem to get it to work without setting that "use local iss web server" path/option.

    On my main project from your provided steps I have the following which is basically just changing the two spots in the Web.config and various ServiceReferences.ClientConfig files to httpsTransport from httpTransport.  Updating my Service References though throws an error as they are looking for the localhost address and not the relative url. 

    	<system.serviceModel>
    		<behaviors>
    			<serviceBehaviors>
              <behavior name="Cvt_New.MainDataBehavior">
    					<serviceMetadata httpGetEnabled="true" />
    					<serviceDebug includeExceptionDetailInFaults="false" />
    				</behavior>
    			</serviceBehaviors>
    		</behaviors>
    		<bindings>
    			<customBinding>
    				<binding name="customBinding0">
    					<binaryMessageEncoding />
    					 <httpsTransport authenticationScheme="Negotiate" />  
              <!-- SILVER LIGHT CONTROL ERRORS? SEE BELOW-->
               <!-- THIS SETTING NEEDS TO BE "Anonymous" if normal authentication, "Ntlm" if you are using PASSTHRU AUTHENTICATION, BUT USE "Negotiate" IF YOU'RE GETTING WINDOWS PROMPT BOX FOR LOG IN while in Passthru-->
    				</binding>
    			</customBinding>
    		</bindings>
    		<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    		<services>
    			<service behaviorConfiguration="Cvt_New.MainDataBehavior" name="Cvt_New.MainData">
    				<endpoint address="" binding="customBinding" bindingConfiguration="customBinding0" contract="Cvt_New.MainData" />
    				<endpoint address="mex" binding="customBinding" bindingConfiguration="customBinding0" contract="IMetadataExchange" />
    			</service>
    		</services>
    	</system.serviceModel>
    
    
    
    <configuration>
        <system.serviceModel>
            <bindings>
                <customBinding>
                    <binding name="CustomBinding_MainData">
                        <binaryMessageEncoding />
                        <httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
                    </binding>
                </customBinding>
            </bindings>
            <client>
                <endpoint address="../MainData.svc" binding="customBinding"
                    bindingConfiguration="CustomBinding_MainData" contract="ServiceReference1.MainData"
                    name="CustomBinding_MainData" />
            </client>
        </system.serviceModel>
    </configuration>
    Monday, October 17, 2011 1:42 PM
  • Updating my Service References though throws an error as they are looking for the localhost address and not the relative url. 

    Just ignore that error.  It will work.

    I never tried to run the app under https protocal using Dev Server and I'm not even sure Dev Server supports that.  I alwasy use IIS if I need to test the app under https.

    After you are done testing your code under DEV server with http protocal, you can create a App under local IIS point to your Web project directory.  Make this app running under HTTPS.  Then test your app by using url such as https://localhost/YourApp/YourPage.html.

    Monday, October 17, 2011 1:49 PM
  • O.K, so changing those areas to be https as stated and updating the ServiceReferences (resulting in that error could not find a base address that matches scheme https for the endpoint with binding CustomBinding) which I just ignore then and then running locally I receive an error saying provided URI scheme 'http' is invalid;it's expecting https...which I'm guessing is right because running locally there is no support for https.

      So deploying this onto my webserver in IIS should then allow the application to successfully access the service without the this last error?

    My first attempt at this resulted in "Error: System.ArgumentException: [InvalidUriScheme] Arguments: https, http Debugging resource strings are unavailable."

    Going to try once more as I had some corruption issues on IIS here and hopefully works

    Monday, October 17, 2011 4:11 PM
  • Once I get to the spot in my application that uses the service I'm still getting this "Error: System.ArgumentException: [InvalidUriScheme] Arguments: https, http Debugging resource strings are unavailable."

    Not sure where to check from here

    Monday, October 17, 2011 4:34 PM
  • Also (though trying this locally) when I make these changes and try to view my service I'm receiving the same error that my ServiceReferences were throwing when I updated them "Could not find a base address that matches scheme https for the endpoint with binding CustomBinding. Registered base address schemes are [http]

    Monday, October 17, 2011 4:43 PM
  • Could you show your ClientConfig and Web.Config?

    Monday, October 17, 2011 4:47 PM
  • ServiceReferences.ClientConfig (all of these for each SL project look the same)
    <configuration>
        <system.serviceModel>
            <bindings>
                <customBinding>
                    <binding name="CustomBinding_MainData">
                        <binaryMessageEncoding />
                        <httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
                    </binding>
                </customBinding>
            </bindings>
            <client>
                <endpoint address="../MainData.svc" binding="customBinding"
                    bindingConfiguration="CustomBinding_MainData" contract="ServiceReference1.MainData"
                    name="CustomBinding_MainData" />
            </client>
        </system.serviceModel>
    </configuration>
     
     
    <authentication mode="Windows">
    			<!--<forms name="Crv" loginUrl="Default.aspx"></forms>-->
    		</authentication>
    		<authorization>
          <!-- for PASSTHRU AUTHENTICATION USE <deny users="?" /> and disable anonymous in IIS, enabling Windows auth.-->
          <!-- for STANDARD AUTHENTICATION USE <allow users="*" /> and enable anonymous in IIS, disabling Windows auth.-->
          <!-- dont forget to update the SILVERLIGHT binding settings in this file also -->
    			<deny users="?" />
    		</authorization>
        <!--
                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>-->
    		<customErrors mode="Off" />
    		<pages enableEventValidation="false" validateRequest="false" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
    			<controls>
    				<add tagPrefix="ajaxtoolkit" namespace="AjaxControlToolkit" assembly="AjaxControlToolKit" />
    			
    			</controls>
    		</pages>
    		
    		<!--maxRequestLength is set to 1GB to limit the size of uploads by rejecting any which exceed the maxRequestLength. ExecutionTimeOut is set to one hour-->
    		<httpRuntime maxRequestLength="1048576" executionTimeout="3600" requestValidationMode="2.0" />
    		<sessionState mode="InProc" stateConnectionString="tcpip=xxx" sqlConnectionString="data source=xxx;Trusted_Connection=yes" cookieless="false" timeout="60" />
    		<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
    		<!--<xhtmlConformance mode="Legacy"/>-->
    	</system.web>
    	<!-- 
            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 runAllManagedModulesForAllRequests="true">
    			
    			
    		</modules>
    		<handlers>
    			
    		...stuff...
    		</handlers>
    		<security>
    			<requestFiltering>
    				<requestLimits maxAllowedContentLength="1073741824" /></requestFiltering>
    		</security>
    		<defaultDocument>
    			<files>
    				<clear />
    				<!-- <remove value="iisstart.htm" />
    				<remove value="index.html" />
    				<remove value="index.htm" />
    				<remove value="Default.asp" />
    				<remove value="Default.htm" /> -->
    				<add value="Default.aspx" />
    			</files>
    		</defaultDocument>		
    	</system.webServer>
    	<system.serviceModel>
    		<behaviors>
    			<serviceBehaviors>
              <behavior name="Crv_New.MainDataBehavior">
    					<serviceMetadata httpGetEnabled="true" />
    					<serviceDebug includeExceptionDetailInFaults="false" />
    				</behavior>
    			</serviceBehaviors>
    		</behaviors>
    		<bindings>
    			<customBinding>
    				<binding name="customBinding0">
    					<binaryMessageEncoding />
    					 <httpsTransport authenticationScheme="Anonymous" />  
              <!-- SILVER LIGHT CONTROL ERRORS? SEE BELOW-->
               <!-- THIS SETTING NEEDS TO BE "Anonymous" if normal authentication, "Ntlm" if you are using PASSTHRU AUTHENTICATION, BUT USE "Negotiate" IF YOU'RE GETTING WINDOWS PROMPT BOX FOR LOG IN while in Passthru-->
    				</binding>
    			</customBinding>
    		</bindings>
    		<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    		<services>
    			<service behaviorConfiguration="Crv_New.MainDataBehavior" name="Crv_New.MainData">
    				<endpoint address="" binding="customBinding" bindingConfiguration="customBinding0" contract="Crv_New.MainData" />
    				<endpoint address="mex" binding="customBinding" bindingConfiguration="customBinding0" contract="IMetadataExchange" />
    			</service>
    		</services>
    	</system.serviceModel>
    </configuration>
    
    Monday, October 17, 2011 4:55 PM
  • ServiceReferences.ClientConfig (all of these for each SL project look the same)
    <configuration>
        <system.serviceModel>
            <bindings>
                <customBinding>
                    <binding name="CustomBinding_MainData">
                        <binaryMessageEncoding />
                        <httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
                    </binding>
                </customBinding>
            </bindings>
            <client>
                <endpoint address="../MainData.svc" binding="customBinding"
                    bindingConfiguration="CustomBinding_MainData" contract="ServiceReference1.MainData"
                    name="CustomBinding_MainData" />
            </client>
        </system.serviceModel>
    </configuration>
     
    WEb.config
    
    <authentication mode="Windows">
    			<!--<forms name="Crv" loginUrl="Default.aspx"></forms>-->
    		</authentication>
    		<authorization>
          <!-- for PASSTHRU AUTHENTICATION USE <deny users="?" /> and disable anonymous in IIS, enabling Windows auth.-->
          <!-- for STANDARD AUTHENTICATION USE <allow users="*" /> and enable anonymous in IIS, disabling Windows auth.-->
          <!-- dont forget to update the SILVERLIGHT binding settings in this file also -->
    			<deny users="?" />
    		</authorization>
        <!--
                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>-->
    		<customErrors mode="Off" />
    		<pages enableEventValidation="false" validateRequest="false" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
    			<controls>
    				<add tagPrefix="ajaxtoolkit" namespace="AjaxControlToolkit" assembly="AjaxControlToolKit" />
    			
    			</controls>
    		</pages>
    		
    		<!--maxRequestLength is set to 1GB to limit the size of uploads by rejecting any which exceed the maxRequestLength. ExecutionTimeOut is set to one hour-->
    		<httpRuntime maxRequestLength="1048576" executionTimeout="3600" requestValidationMode="2.0" />
    		<sessionState mode="InProc" stateConnectionString="tcpip=xxx" sqlConnectionString="data source=xxx;Trusted_Connection=yes" cookieless="false" timeout="60" />
    		<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
    		<!--<xhtmlConformance mode="Legacy"/>-->
    	</system.web>
    	<!-- 
            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 runAllManagedModulesForAllRequests="true">
    			
    			
    		</modules>
    		<handlers>
    			
    		...stuff...
    		</handlers>
    		<security>
    			<requestFiltering>
    				<requestLimits maxAllowedContentLength="1073741824" /></requestFiltering>
    		</security>
    		<defaultDocument>
    			<files>
    				<clear />
    				<!-- <remove value="iisstart.htm" />
    				<remove value="index.html" />
    				<remove value="index.htm" />
    				<remove value="Default.asp" />
    				<remove value="Default.htm" /> -->
    				<add value="Default.aspx" />
    			</files>
    		</defaultDocument>		
    	</system.webServer>
    	<system.serviceModel>
    		<behaviors>
    			<serviceBehaviors>
              <behavior name="Crv_New.MainDataBehavior">
    					<serviceMetadata httpGetEnabled="true" />
    					<serviceDebug includeExceptionDetailInFaults="false" />
    				</behavior>
    			</serviceBehaviors>
    		</behaviors>
    		<bindings>
    			<customBinding>
    				<binding name="customBinding0">
    					<binaryMessageEncoding />
    					 <httpsTransport authenticationScheme="Anonymous" />  
              <!-- SILVER LIGHT CONTROL ERRORS? SEE BELOW-->
               <!-- THIS SETTING NEEDS TO BE "Anonymous" if normal authentication, "Ntlm" if you are using PASSTHRU AUTHENTICATION, BUT USE "Negotiate" IF YOU'RE GETTING WINDOWS PROMPT BOX FOR LOG IN while in Passthru-->
    				</binding>
    			</customBinding>
    		</bindings>
    		<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    		<services>
    			<service behaviorConfiguration="Crv_New.MainDataBehavior" name="Crv_New.MainData">
    				<endpoint address="" binding="customBinding" bindingConfiguration="customBinding0" contract="Crv_New.MainData" />
    				<endpoint address="mex" binding="customBinding" bindingConfiguration="customBinding0" contract="IMetadataExchange" />
    			</service>
    		</services>
    	</system.serviceModel>
    </configuration>
    
    Monday, October 17, 2011 5:12 PM
  • I created a helper class to initialize my service clients like so:

    using System.ServiceModel.Channels;
    using System.Windows;

        public class WCFServiceExtension
        {
            public WCFServiceExtension()
            {
            }

            public static WCFServiceReference.WCFServiceClient InitializeWCFServiceClient()
            {
                return new WCFServiceReference.WCFServiceClient(WCFServiceExtension.GetServiceBinding(), new System.ServiceModel.EndpointAddress(GetWebSiteRoot() + "WCFService.svc"));
            }

            public static CustomBinding GetServiceBinding()
            {
                CustomBinding binding = new CustomBinding();
                binding.Elements.Add(new BinaryMessageEncodingBindingElement());
                if (Application.Current.Host.Source.Scheme.Equals("https"))
                {
                    binding.Elements.Add(new HttpsTransportBindingElement() { MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue });
                }
                else
                {
                    binding.Elements.Add(new HttpTransportBindingElement() { MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue });
                }
                return binding;
            }

            public static string GetWebSiteRoot()
            {
                string rootURL = Application.Current.Host.Source.OriginalString;
                rootURL = rootURL.Substring(0, rootURL.LastIndexOf("ClientBin"));
                return rootURL;
            }
        }

    Then, to initialize the client:

    WCFServiceReference.WCFServiceClient wcfClient = WCFServiceExtension.InitializeWCFServiceClient();

    This assumes the service is hosted at the root of the same web site as the silverlight application.  You may need to modify the GetWebSiteRoot() according to suit your needs.

    Tuesday, October 18, 2011 8:22 AM
  • Rob working with your code provided (haven't used the helper class yet) I have the following for the web.config portion and then for the ServiceReferences.ClientConfig I'm guessing the only change is making the transport <httpsTransport>?

    With this in place and running I'm hitting the notorious road block System.ArgumentException:[InvalidUrlScheme] Arguments:https, http 

    <system.serviceModel>
    		<behaviors>
    			<serviceBehaviors>
    				<behavior name="Crv_New.MainDataBehavior">
    					<serviceMetadata httpsGetEnabled="true" httpGetBinding="true" />
    					<serviceDebug includeExceptionDetailInFaults="true" />
    					<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    				</behavior>
    			</serviceBehaviors>
    		</behaviors>
    		<diagnostics>
    			<messageLogging logEntireMessage="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true"/>
    		</diagnostics>
    		<bindings>
    			<customBinding>
    				<binding name="customBinding0" closeTimeout="00:20:00" openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00">
    					<binaryMessageEncoding maxReadPoolSize="2147483647" maxWritePoolSize="2147483647" maxSessionSize="2147483647">
    						<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
    					</binaryMessageEncoding>
    					<httpTransport maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" authenticationScheme="Negotiate" maxBufferSize="2147483647" transferMode="Buffered"/>
    				</binding>
    				<binding name="customBinding0https" closeTimeout="00:20:00" openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00">
    					<binaryMessageEncoding maxReadPoolSize="2147483647" maxWritePoolSize="2147483647" maxSessionSize="2147483647">
    						<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
    					</binaryMessageEncoding>
    					<httpsTransport maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" authenticationScheme="Negotiate" maxBufferSize="2147483647" transferMode="Buffered"/>
    				</binding>
    			</customBinding>
    		</bindings>
    
    		<!--<httpsTransport authenticationScheme="Negotiate" />-->
    		<!-- SILVER LIGHT CONTROL ERRORS? SEE BELOW-->
    		<!-- THIS SETTING NEEDS TO BE "Anonymous" if normal authentication, "Ntlm" if you are using PASSTHRU AUTHENTICATION, BUT USE "Negotiate" IF YOU'RE GETTING WINDOWS PROMPT BOX FOR LOG IN while in Passthru-->
    		<!--</binding>
    			</customBinding>
    		</bindings>-->
    		<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    		<services>
    			<service behaviorConfiguration="Crv_New.MainDataBehavior" name="Crv_New.MainData">
    				<endpoint address="" binding="customBinding" bindingConfiguration="customBinding0" contract="Crv_New.MainData" />
    				<endpoint address="mex" binding="customBinding" bindingConfiguration="customBinding0" contract="IMetadataExchange" />
    				<endpoint address="" binding="customBinding" bindingConfiguration="customBinding0https" contract="Crv_New.MainData" />
    			</service>
    		</services>
    	</system.serviceModel>
    </configuration><system.serviceModel>
    		<behaviors>
    			<serviceBehaviors>
    				<behavior name="Crv_New.MainDataBehavior">
    					<serviceMetadata httpsGetEnabled="true" httpGetBinding="true" />
    					<serviceDebug includeExceptionDetailInFaults="true" />
    					<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    				</behavior>
    			</serviceBehaviors>
    		</behaviors>
    		<diagnostics>
    			<messageLogging logEntireMessage="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true"/>
    		</diagnostics>
    		<bindings>
    			<customBinding>
    				<binding name="customBinding0" closeTimeout="00:20:00" openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00">
    					<binaryMessageEncoding maxReadPoolSize="2147483647" maxWritePoolSize="2147483647" maxSessionSize="2147483647">
    						<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
    					</binaryMessageEncoding>
    					<httpTransport maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" authenticationScheme="Negotiate" maxBufferSize="2147483647" transferMode="Buffered"/>
    				</binding>
    				<binding name="customBinding0https" closeTimeout="00:20:00" openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00">
    					<binaryMessageEncoding maxReadPoolSize="2147483647" maxWritePoolSize="2147483647" maxSessionSize="2147483647">
    						<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
    					</binaryMessageEncoding>
    					<httpsTransport maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" authenticationScheme="Negotiate" maxBufferSize="2147483647" transferMode="Buffered"/>
    				</binding>
    			</customBinding>
    		</bindings>
    
    		<!--<httpsTransport authenticationScheme="Negotiate" />-->
    		<!-- SILVER LIGHT CONTROL ERRORS? SEE BELOW-->
    		<!-- THIS SETTING NEEDS TO BE "Anonymous" if normal authentication, "Ntlm" if you are using PASSTHRU AUTHENTICATION, BUT USE "Negotiate" IF YOU'RE GETTING WINDOWS PROMPT BOX FOR LOG IN while in Passthru-->
    		<!--</binding>
    			</customBinding>
    		</bindings>-->
    		<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    		<services>
    			<service behaviorConfiguration="Crv_New.MainDataBehavior" name="Crv_New.MainData">
    				<endpoint address="" binding="customBinding" bindingConfiguration="customBinding0" contract="Crv_New.MainData" />
    				<endpoint address="mex" binding="customBinding" bindingConfiguration="customBinding0" contract="IMetadataExchange" />
    				<endpoint address="" binding="customBinding" bindingConfiguration="customBinding0https" contract="Crv_New.MainData" />
    			</service>
    		</services>
    	</system.serviceModel>
    </configuration>
     
    <configuration>
        <system.serviceModel>
            <bindings>
                <customBinding>
                    <binding name="CustomBinding_MainData">
                        <binaryMessageEncoding />
                        <httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
                    </binding>
                </customBinding>
            </bindings>
            <client>
                <endpoint address="../MainData.svc" binding="customBinding"
                    bindingConfiguration="CustomBinding_MainData" contract="ServiceReference1.MainData"
                    name="CustomBinding_MainData" />
            </client>
        </system.serviceModel>
    </configuration>
    Tuesday, October 18, 2011 9:47 AM
  • I think that's due to: address="../MainData.svc"  I went through end cleaned up your web.config, it should look like:

     

    <system.serviceModel>
                    <behaviors>
                            <serviceBehaviors>
                                    <behavior name="WCFServiceBehavior">
                                            <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                                            <serviceDebug includeExceptionDetailInFaults="true" />
                                            <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
                                    </behavior>
                            </serviceBehaviors>
                    </behaviors>
                    <diagnostics>
                            <messageLogging logEntireMessage="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true"/>
                    </diagnostics>
                    <bindings>
                            <customBinding>
                                    <binding name="binaryHttpBinding" closeTimeout="00:20:00" openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00">
                                            <binaryMessageEncoding maxReadPoolSize="2147483647" maxWritePoolSize="2147483647" maxSessionSize="2147483647">
                                                    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
                                            </binaryMessageEncoding>
                                            <httpTransport maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" authenticationScheme="Negotiate" maxBufferSize="2147483647" transferMode="Buffered"/>
                                    </binding>
                                    <binding name="binaryHttpsBinding" closeTimeout="00:20:00" openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00">
                                            <binaryMessageEncoding maxReadPoolSize="2147483647" maxWritePoolSize="2147483647" maxSessionSize="2147483647">
                                                    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
                                            </binaryMessageEncoding>
                                            <httpsTransport maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" authenticationScheme="Negotiate" maxBufferSize="2147483647" transferMode="Buffered"/>
                                    </binding>
                            </customBinding>
                    </bindings>
                    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
                    <services>
                            <service behaviorConfiguration="WCFServiceBehavior" name="Crv_New.MainData">
                                    <endpoint address="" binding="customBinding" bindingConfiguration="binaryHttpBinding" contract="Crv_New.MainData" />
                                    <endpoint address="" binding="customBinding" bindingConfiguration="binaryHttpsBinding" contract="Crv_New.MainData" />
                            </service>
                    </services>
    </system.serviceModel>

     

    After you fix up the web.config, regenerate your service.reference in your silvleright application.

    Tuesday, October 18, 2011 11:05 AM
  • As my service is part of the application (sits in my asp.net project at the root) isn't this the proper syntax (relative)? 

    Also, In my ServiceReferences.ClientConfig do I need seperate bindings for both https and http like below? And just one endpoint?

    <configuration>
        <system.serviceModel>
            <bindings>
                <customBinding>
                    <binding name="CustomBinding_MainData">
                        <binaryMessageEncoding />
                        <httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
                    </binding>
    <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
                    </binding>
    
                </customBinding>
            </bindings>
            <client>
                <endpoint address="../MainData.svc" binding="customBinding"
                    bindingConfiguration="CustomBinding_MainData" contract="ServiceReference1.MainData"
                    name="CustomBinding_MainData" />
            </client>
        </system.serviceModel>
    </configuration>
    Tuesday, October 18, 2011 11:21 AM
  • Yes you need spereate bindings, I dont think xaml not supports relative urls.  You will notice when you generate the servicereference.clientcongfi it uses the fully qualified url.  But if you use the method I posted earlier, it will ignore your servicereference.client config.

    Tuesday, October 18, 2011 11:38 AM
  • O.k so I added another binding under my ServiceReferences.ClientConfig so there are two now

    <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />

    <httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />

    as far as the endpoint address I'm not sure what that should be then as running locally I'd be using http://localhost:4495/MainData.svc and that obviously wont work when publishing out to my webserver (C\inetpub\wwwroot\myproject)

    Also, updating my ServiceReferences after the web.config changes you supplied always result in an error because I have that relative path set and it's looking for the localhost path.  So am I supposed to just set that to the absolute path of where its going to reside on the webserver?

    Is doing this locally and publishing it out to the webserver adding to the complication of this in someway vs having VS installed on the webserver and doing it there?  Just trying to figure out the best way to do this here...thx for all your help Rob

    Tuesday, October 18, 2011 12:02 PM
  • O.K so I added that helper class into one of my Silverlight Projects and it's complaining about the public static WCFServiceReference.WCFServiceClient InitializeWCFServiceClient()

    using System;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.ServiceModel.Channels;
    
    namespace slGridAppFull
    {
        public class WCFServiceExtension
        {
            public WCFServiceExtension()
            {
            }
    
            public static WCFServiceReference.WCFServiceClient InitializeWCFServiceClient()
            {
                return new WCFServiceReference.WCFServiceClient(WCFServiceExtension.GetServiceBinding(), new System.ServiceModel.EndpointAddress(GetWebSiteRoot() + "WCFService.svc"));
            }
    
            public static CustomBinding GetServiceBinding()
            {
                CustomBinding binding = new CustomBinding();
                binding.Elements.Add(new BinaryMessageEncodingBindingElement());
                if (Application.Current.Host.Source.Scheme.Equals("https"))
                {
                    binding.Elements.Add(new HttpsTransportBindingElement() { MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue });
                }
                else
                {
                    binding.Elements.Add(new HttpTransportBindingElement() { MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue });
                }
                return binding;
            }
    
            public static string GetWebSiteRoot()
            {
                string rootURL = Application.Current.Host.Source.OriginalString;
                rootURL = rootURL.Substring(0, rootURL.LastIndexOf("ClientBin"));
                return rootURL;
            }
        }
    }

    The initialzation part at the end you posted would go in my MainPage.xaml.cs I'm guessing, but I'm unable to do anything other than WCFServiceExtension.InitializeWCFServiceClient(); without it complaining.

    public MainPage()

    {

    InitializeComponent();

    }

    Tuesday, October 18, 2011 12:37 PM
  • Tuesday, October 18, 2011 1:00 PM
  • Well done Sally!  With the number of posts on this subject I'm surprised this hasn't been done sooner.  I just hope this info doesn't get lost in the bowels of the forum...

    Tuesday, October 18, 2011 1:08 PM
  • Nice write up and I'm working through this....Step 9 though with the way my current project is setup doesn't have the Web projects for my Silverlight apps.  When importing the SL apps into my main asp.net application from what I recall you indicated I didn't need those and so I removed them as they aren't needed.  Can I still get around that step somehow?  Is it just for testing purposes?

    Also because of that my ServiceReferences.ClientConfig still shows as such:

    <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" />
            </client>
        </system.serviceModel>
    </configuration>
     
    Does this also need to change? Am I going to have to drop all my SL projects to set this up and readd them and remove the web portion of them again?
    Tuesday, October 18, 2011 1:51 PM
  • Step 9 though with the way my current project is setup doesn't have the Web projects for my Silverlight apps.  When importing the SL apps into my main asp.net application from what I recall you indicated I didn't need those and so I removed them as they aren't needed. 

    You must have a main Web project which contains your WCF service, your pages and the web config file, right? It doesn't matter if it was created with the Silverlight project or it was an existing Web project.

    If you use the WCFHelper code,  the ClientConfig is no longer used. So we don't care what is in that file anymore. 

    You can follow each step to create a test project before doing anything to your own project. Once you understand each step, you can apply the knowledge to your own project to make it work which should be very simple.

    Tuesday, October 18, 2011 2:01 PM
  • O.k...so that helper code bypasses the servRef...got'cha.  When I created each SL project it has the service, but when adding it into the main asp.net project the service is then added to that and the web portion of the SL app isn't needed any longer (below clipped of code from your help previously) 

    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"

     

    Tuesday, October 18, 2011 2:13 PM
  • nvm...I see your probably referring to the web portion of my main application.  Sorry

    Tuesday, October 18, 2011 2:19 PM
  • Yes, that  ASP.NET project is your main Web project in your case. Just do everything on that Project as I refer to the Web project in my blog.  If your project name is "XXX", make sure to change the URL to refer to your project name, not mine.

    Tuesday, October 18, 2011 2:19 PM
  • Sally I'm guessing you performed these steps from within your webserver enviornment as locally I cannot set the virtual directory path of my IIS server running VS locally?

    Tuesday, October 18, 2011 2:36 PM
  • Sally I'm guessing you performed these steps from within your webserver enviornment as locally I cannot set the virtual directory path of my IIS server running VS locally?

    I'm not sure I understand you.

    Tuesday, October 18, 2011 2:39 PM
  • Trying to do this from my local pc that doesn't have IIS on it, wont allow me to map that virtual path.  I'm now working with this from my WebServer in IIS and mapping to the virtual directory path works  (https://localhost/crv_New) and naviagating to my service works in both https and http.  so all looks good except I cant navigate to my Default.aspx page now as such https://localhost/crv_New/Default.aspx  same story trying with just http.  So I can access the service just not my login page now?

    Tuesday, October 18, 2011 3:24 PM
  • Every PC has IIS on it. You just need to turn the feature on.

    If you really can't test it locally first (it is just easier to do it this way without deploy it first), you can skip step 9 and 10. 

    But before deploy your app you want to modify the web.config first. So go to Step 14 to modify the web.config file.

    Deploy the app to your IIS. Make sure to test your service under SSL first.  Then your app.

    Tuesday, October 18, 2011 3:40 PM
  • yeah on my pc it looks like I have the feature turned on and can map the virtual to an http://whatever, just not https://whatever

    Tuesday, October 18, 2011 4:07 PM
  • You need to enable SSL on your IIS. Read the article in step 10 to enable SSL on your Application under IIS.

    Tuesday, October 18, 2011 4:39 PM
  • Finally.....working.  I cant thank the both of you enough for helping me through this setup and getting it working.  Thank You for all your help.

    Tuesday, October 18, 2011 5:31 PM
  • Glad it's working. Don't forget to mark answer on this thread.

    Tuesday, October 18, 2011 7:41 PM
  • Hi trag1,

    In order to access WCF service using https, you need to consider followings:

    1) Binding should be like this:

    <basicHttpBinding>
    <binding name="MyHttpsBinding" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
    <readerQuotas maxDepth="1200" maxArrayLength="2147483647"/>
    <security mode="Transport">
    <transport clientCredentialType="None"/>
    </security>
    </binding>
    </basicHttpBinding>

    2) In behavior, you need to configure certificate for service. So service can check https encryption against specified certificate. Behavior should be like this:

    <behavior name="MyBehaviorForHttps">
    <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"/>
    <serviceDebug includeExceptionDetailInFaults="true"/>
    <serviceCredentials>
    <clientCertificate>
    <authentication certificateValidationMode="PeerOrChainTrust" revocationMode="NoCheck"/>
    </clientCertificate>
    <serviceCertificate findValue="0f dd a9 cd 56 12 be fa f0 64 c5 3b 9f e8 32 4c 39 4b 74 c0" x509FindType="FindByThumbprint"/>
    </serviceCredentials>
    </behavior>

    Certificate must be exists in machine's store.

    3) Now apply this binding and behavior in service's configuration.

    Now service will allow https communication.

     

    Wednesday, October 19, 2011 1:34 AM
  • Oh My God, I try to find myself in all this.

    All we want is to have our Silverlight app reachable by HTTP from the inside of the office (INTRANET) and then by HTTPS from the outside (EXTRANET)
    I tried all possible combination of binding since 2 days in a row in Visual Studio 2012 but always end up with all kind of error when UPDATING THE SERVICE REFERENCE

    I don't know what it involve for configuration in IIS and I'm not the expert for it so I wouldn't understand what to do on this side of things.  Now what I see is that the app is working pretty fine in HTTP from the inside, it loads from outside by the HTTPS but nothing works. I mean by that the WCF calls seems not working and nothing returns from the server to the client  So Yes I know that actually everything I have configured is for http in my Web.config but since I tried so many combination of things from here and from the internet without having the real solution yet.

    and YES we created the clientaccesspolicy.xml and placed it in the root folder of the app
    What bugs me is I'm unable to update my service reference with configuration for both HTTP and HTTPS whatever I try to do I always have errors.

    Here's my actual Web.Config.  Understand that this is what it actually looks like because I'm still trying all kind of combination

    <?xml version="1.0"?>
    
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    
    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5" />
      </system.web>
      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior name="SLExpenseAccounts.Web.AppBehavior">
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
              <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <diagnostics>
          <messageLogging logEntireMessage="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true"/>
        </diagnostics>
        <bindings>
          <basicHttpBinding>
            <binding name="httpBinding"
                     maxBufferSize="2147483647"
                     maxBufferPoolSize="2147483647"
                     maxReceivedMessageSize="2147483647">
              <readerQuotas maxDepth="2147483647"
                      maxStringContentLength="2147483647"
                      maxArrayLength="2147483647"
                      maxBytesPerRead="2147483647"
                      maxNameTableCharCount="2147483647"/>
            </binding>
          </basicHttpBinding>
          <customBinding>
            <binding name="HttpsBinding" closeTimeout="00:20:00" openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00">
              <binaryMessageEncoding maxReadPoolSize="2147483647" maxWritePoolSize="2147483647" maxSessionSize="2147483647">
                <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
              </binaryMessageEncoding>
              <httpsTransport maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" authenticationScheme="Anonymous" maxBufferSize="2147483647" transferMode="Buffered"/>
            </binding>
          </customBinding>
        </bindings>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
            multipleSiteBindingsEnabled="false" />
        <services>
          <service name="SLExpenseAccounts.Web.Service" behaviorConfiguration="SLExpenseAccounts.Web.AppBehavior">
            <endpoint address="" binding="basicHttpBinding" contract="SLExpenseAccounts.Web.Service"
                      name="HTTPEndPoint" bindingConfiguration="httpBinding"/>
            <endpoint address="https://SOME DOMAIN/Service.svc" binding="customBinding" contract="SLExpenseAccounts.Web.Service"
                      name="HTTPSEndPoint" bindingConfiguration="HttpsBinding"/>
            <host>
              <baseAddresses>
                <add baseAddress="../Service.svc"/>
              </baseAddresses>
            </host>
          </service>
        </services>
      </system.serviceModel>
    </configuration>

    This actual version which is the 37th alretation I tried is giving : The protocol https is not supported

    I have to add to this the fact that they seem to have made a server HTTPS that reaches the HTTP one where the service is hosted  I don't know how they do that but seems that the SL is not capable of reaching the HTTP by passing from another server which is HTTPS to reach the service
    However the service.svc is reachable from HTTP inside the domain and by HTTPS outside the domain so why SL is not able to function when I add the second binding in the Web.Config even thought the the ServiceReference.ClientConfig is set to reach both endpoints.  Does that means that where the service is hosted that the HTTPS must be enabled along with the SSL ?

    I don't know I'm just guessing out loud.

    • Edited by GearWorld Sunday, May 12, 2013 11:50 AM
    Saturday, May 11, 2013 4:19 PM