Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Deployment of Silverlight App + Silverlight-Enabled WCF... RSS

76 replies

Last post Jan 04, 2012 09:38 PM by Henning Flessner

(0)
  • BlasterX

    BlasterX

    Member

    5 Points

    13 Posts

    Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

    Jun 24, 2008 08:50 PM | LINK

    I have a silverlight application that uses a silverlight enabled WCF service. all in one solution. It works with no problem on the visual studio development server (localhost with a random port number). 

    If I deploy the entire website (App and WCF) to IIS, the Silverlight app works correctly, but it can't access/use the WCF service properly and an error occurs. I haven't been able to figure out what's wrong with it.

     Does anyone have a step-by-step tutorial or can explain to me what has to be done to get a silverlight app to find the WCF service? (I have just been using the "add service reference" option in visual studio for local use/testing.

  • davesmits

    davesmits

    Member

    631 Points

    210 Posts

    Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

    Jun 24, 2008 09:01 PM | LINK

    If you have vista or windows 2003 on your development server you can try to use IIS on your development computer and try to get it works;

  • BlasterX

    BlasterX

    Member

    5 Points

    13 Posts

    Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

    Jun 24, 2008 09:08 PM | LINK

    Thank you for the suggestion. My "production" environment is the same computer I use to run visual studio and build my projects. The only difference is running the website off of IIS rather than visual studio attached to a specific port.

     

     

  • davesmits

    davesmits

    Member

    631 Points

    210 Posts

    Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

    Jun 24, 2008 09:13 PM | LINK

    agree; weird. I personaly got everything working fine on my development computer and using IIS for testing.

     

    How do you set your endpoint in your silverlight application?

  • sladapter

    sladapter

    All-Star

    43607 Points

    7907 Posts

    Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

    Jun 24, 2008 09:23 PM | LINK

    Check the url set for your Service in your ServiceReference.ClientConfig file. If the URL is like http://localhost:Port#/YourService.svc then that is your problem.

    When you add Service Reference when you develop,  The URL is generated by the Dev Web Server which contains a Port number. When you deploy your project to IIS. This url for your service is no longer valid. You have several options.

    1) Change the URL to a real URL in the  ServiceReference.ClientConfig before your final build.

    2) If you already deployed your .Xap file to the server, and you do not want to rebuild it. You can use a WinRar (download for free) tool to extract the  ServiceReference.ClientConfig file out, edit the url, then use the same tool to zip it back to the .Xap file.

    3) Do not rely on the URL set in the ServiceReference.ClientConfig. Set your URL in the code.  Change your WebSerivice Calling code to the following:

              var webService = new YourWebService.YourWebServiceClient() // This is the default constructor, url will be read from the clientconfig file.

              Uri address = new Uri(Application.Current.Host.Source, "../YourService.svc"); // this url will work both in dev and after deploy.

              var webService = new YourWebService.YourWebServiceClient("YourServiceEndPointName", address.AbsolutePath);


    I like the option 3 better if you sure WebService file will stay at the same Web Site as your Silverlight page.

    During development, the Port number is also changing from time to time. If you close your VS, then come back again later, that port number might changed to a new one. So unless you update your Service reference regularly, your Port number for your page might be not consistant with the port number in the service url in the clientconfig file. This causes cross-domain call even both service and page are in the same project. Setting the URL in the code should avoid this problem.


     

     

         

    Sally Xu
    Software Engineer
    Aprimo, Inc

    Please remember to mark the replies as answers if they answered your question
  • BlasterX

    BlasterX

    Member

    5 Points

    13 Posts

    Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

    Jun 24, 2008 09:26 PM | LINK

     This is how I have it set up in the web config:

    <system.serviceModel>
            <behaviors>
                <serviceBehaviors>
                    <behavior name="MathServiceBehavior">
                        <serviceMetadata httpGetEnabled="true"/>
                        <serviceDebug includeExceptionDetailInFaults="false"/>
                    </behavior>
                </serviceBehaviors>
            </behaviors>
            <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
            <services>
                <service behaviorConfiguration="MathServiceBehavior" name="MathService">
                    <endpoint address="http://localhost:3046/RegressionToolWeb/MathService.svc" binding="basicHttpBinding" contract="MathService"/>
                    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
                </service>
            </services>
        </system.serviceModel>

     This is how I have it set up in the ClientConfig

    <system.serviceModel>
            <bindings>
                <basicHttpBinding>
                    <binding name="BasicHttpBinding_MathService" maxBufferSize="65536"
                        maxReceivedMessageSize="65536">
                        <security mode="None" />
                    </binding>
                </basicHttpBinding>
            </bindings>
            <client>
                <endpoint address="http://localhost:3046/RegressionToolWeb/MathService.svc"
                    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_MathService"
                    contract="RegressionTool.MathServiceReference.MathService"
                    name="BasicHttpBinding_MathService" />
            </client>
        </system.serviceModel>

     

    A note that I tried removing the port number completely and setting it to port (80) in both the Server/Client config files and had no luck.

     

  • sladapter

    sladapter

    All-Star

    43607 Points

    7907 Posts

    Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

    Jun 24, 2008 09:31 PM | LINK

    You need to change this url

    http://localhost:3046/RegressionToolWeb/MathService.svc

    to a real url, if you are running it on IIS on your machine:

     http://localhost/RegressionToolWeb/MathService.svc

    or

      http://YourMachineName/RegressionToolWeb/MathService.svc

     

    Depending how you run your silverlight page, If your page url is :http://localhost/RegressionToolWeb/SilverlightTestPage.html

    set the URL =  http://localhost/RegressionToolWeb/MathService.svc

    if your page url is :http://YourMachineName/RegressionToolWeb/SilverlightTestPage.html

    http://YourMachineName/RegressionToolWeb/MathService.svc

    Otherwise you will have cross-domain issue unless you have clientaccesspolicy.xml in your wwwroot folder. 

    So the best way to avoid all these trouble is to use the method 3 I posted.

     

    Sally Xu
    Software Engineer
    Aprimo, Inc

    Please remember to mark the replies as answers if they answered your question
  • BlasterX

    BlasterX

    Member

    5 Points

    13 Posts

    Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

    Jun 25, 2008 02:45 PM | LINK

    I have tried just removing the Port number and have had no luck, but what I tried was accessing the page of the web-service using my browser (so I knew where it was).

     When I tried to access the MathService.svc file this way, I got the following error in my browser: 

    XML Parsing Error: not well-formed
    Location: http://localhost/RegressionToolWeb/MathService.svc
    Line Number 1, Column 2:<%@ ServiceHost Language="C#" Debug="true" Service="MathService" CodeBehind="~/App_Code/MathService.cs" %>
    -^

     I was under the impression that the svc file was just supposed to be a one line auto-generated file that just pointed to the C# code file the service is implemented in. Is there more you are supposed to add or is there a mistake here somewhere?

     It seems to me that the path and config are finding the svc file but that it isn't being hosted properly for some reason and therefore doesn't work.

     

  • sladapter

    sladapter

    All-Star

    43607 Points

    7907 Posts

    Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

    Jun 25, 2008 02:52 PM | LINK

     try this:

    3) Do not rely on the URL set in the ServiceReference.ClientConfig. Set your URL in the code.  Change your WebSerivice Calling code to the following:

              var webService = new YourWebService.YourWebServiceClient() // This is the default constructor, url will be read from the clientconfig file.

              Uri address = new Uri(Application.Current.Host.Source, "../YourService.svc"); // this url will work both in dev and after deploy.

              var webService = new YourWebService.YourWebServiceClient("YourServiceEndPointName", address.AbsolutePath);

    Sally Xu
    Software Engineer
    Aprimo, Inc

    Please remember to mark the replies as answers if they answered your question
  • BlasterX

    BlasterX

    Member

    5 Points

    13 Posts

    Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

    Jun 25, 2008 03:19 PM | LINK

    sladapter

     try this:

    3) Do not rely on the URL set in the ServiceReference.ClientConfig. Set your URL in the code.  Change your WebSerivice Calling code to the following:

              var webService = new YourWebService.YourWebServiceClient() // This is the default constructor, url will be read from the clientconfig file.

              Uri address = new Uri(Application.Current.Host.Source, "../YourService.svc"); // this url will work both in dev and after deploy.

              var webService = new YourWebService.YourWebServiceClient("YourServiceEndPointName", address.AbsolutePath);

     

    I gave this a try too and it didn't work. I got an error stating "Uri Format Exception"

    Uri address = new Uri(Application.Current.Host.Source, "../MathService.svc");
    MathServiceReference.MathServiceClient MathClient = new MathServiceReference.MathServiceClient("BasicHttpBinding_MathService", address.AbsolutePath);

    OR

    Uri address = new Uri(Application.Current.Host.Source, "../MathService.svc");
    MathServiceReference.MathServiceClient MathClient = new MathServiceReference.MathServiceClient("MathService", address.AbsolutePath);

    When you said "YourServiceEndPointName" did you actually mean the "name" attribute? I tried both the name attribute client and server side.

     Web.config:

        <service behaviorConfiguration="MathServiceBehavior" name="MathService">
                    <endpoint name="MathService" address="http://localhost:3046/RegressionToolWeb/MathService.svc" binding="basicHttpBinding" contract="MathService"/>
                    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
                </service>

    ServiceReferences.ClientConfig:

    <client>
                <endpoint address="http://localhost:3046/RegressionToolWeb/MathService.svc"
                    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_MathService"
                    contract="RegressionTool.MathServiceReference.MathService"
                    name="BasicHttpBinding_MathService" />
            </client>

                

    This is more annoying than I expected :-D