Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production
Last post 08-17-2008 7:34 PM by GearWorld. 49 replies.
Sort Posts:
06-24-2008 3:50 PM
Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

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.

BlasterX

Loading...
Joined on 06-20-2008
Posts 13
06-24-2008 4:01 PM
Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

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;

Grtz Dave
http://www.familie-smits.com

davesmits

Loading...
Joined on 08-02-2007
Nederhorst den Berg, Netherlands
Posts 157
06-24-2008 4:08 PM
Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

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.

 

 

BlasterX

Loading...
Joined on 06-20-2008
Posts 13
06-24-2008 4:13 PM
Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

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?

Grtz Dave
http://www.familie-smits.com

davesmits

Loading...
Joined on 08-02-2007
Nederhorst den Berg, Netherlands
Posts 157
06-24-2008 4:23 PM
Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

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.


 

 

     

sladapter
Software Engineer
Aprimo, Inc

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

sladapter

Loading...
Joined on 03-05-2008
Indiana, US
Posts 2,164
06-24-2008 4:26 PM
Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

 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.

 

BlasterX

Loading...
Joined on 06-20-2008
Posts 13
06-24-2008 4:31 PM
Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

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.

 

sladapter
Software Engineer
Aprimo, Inc

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

sladapter

Loading...
Joined on 03-05-2008
Indiana, US
Posts 2,164
06-25-2008 9:45 AM
Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

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.

 

BlasterX

Loading...
Joined on 06-20-2008
Posts 13
06-25-2008 9:52 AM
Marked as Answer
Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

 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);

sladapter
Software Engineer
Aprimo, Inc

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

sladapter

Loading...
Joined on 03-05-2008
Indiana, US
Posts 2,164
06-25-2008 10:19 AM
Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

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

BlasterX

Loading...
Joined on 06-20-2008
Posts 13
06-25-2008 10:44 AM
Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

 Sorry, should be address.AbsoluteUrl. I was just typing from my memory.

MathServiceReference.MathServiceClient MathClient = new MathServiceReference.MathServiceClient("BasicHttpBinding_MathService", address.AbsoluteUrl);

sladapter
Software Engineer
Aprimo, Inc

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

sladapter

Loading...
Joined on 03-05-2008
Indiana, US
Posts 2,164
06-25-2008 11:34 AM
Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

 

sladapter:

 Sorry, should be address.AbsoluteUrl. I was just typing from my memory.

MathServiceReference.MathServiceClient MathClient = new MathServiceReference.MathServiceClient("BasicHttpBinding_MathService", address.AbsoluteUrl);

 

This worked for me locally, but not on production, I get the same kind of error as before.

Regardless of whether I try changing ports or using the method above, Internet Explorer gives me the same error in the bottom left corner, that when clicked says:

Line: 1

Char: 1

Error: Unhandled Error in Silverlight 2 Application Exception has been thrown by the target of an invocation at System.RuntimeMethodHandle_InvokeMethodFast...


BlasterX

Loading...
Joined on 06-20-2008
Posts 13
06-25-2008 11:41 AM
Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

This method (the only one of 3) should work for all cases as long as your Service.svc is at the same site as your Silverlight HTML/ASPX page.

 

If you want to catch the real error, put the following code in your app.xaml.cs Application_UnhandledException function:

 private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
        {
            System.Windows.Browser.HtmlPage.Window.Alert(ex.Message);         
            e.Handled = true;
        }

 

sladapter
Software Engineer
Aprimo, Inc

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

sladapter

Loading...
Joined on 03-05-2008
Indiana, US
Posts 2,164
06-25-2008 11:54 AM
Marked as Answer
Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

  Or you can try this code. It always worked for me.

  System.ServiceModel.BasicHttpBinding binding = new System.ServiceModel.BasicHttpBinding();
        
  System.ServiceModel.EndpointAddress address = new System.ServiceModel.EndpointAddress(new Uri(Application.Current.Host.Source, "../YourService.svc"));

 MathServiceReference.MathServiceClient MathClient = new MathServiceReference.MathServiceClient(binding, address);

 

sladapter
Software Engineer
Aprimo, Inc

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

sladapter

Loading...
Joined on 03-05-2008
Indiana, US
Posts 2,164
06-25-2008 2:12 PM
Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

 Unfortunately it is the same problem even with the code you just suggested.

 I took your advice and added a pop-up that gives me an error message. It seems from looking at it that for some reason it can't find the web service.

 I have my MathService.svc file in the root of the web project (same place as Web.config) and the MathService.cs codebehind file in the App_Code folder. MathService.svc has its path set to "~/App_Code/MathService.cs"

 Here is a picture of the error message:

 

Any ideas what it might be? Crying

BlasterX

Loading...
Joined on 06-20-2008
Posts 13
06-25-2008 2:40 PM
Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

Could you type the following URL in your browser to see what do you get?

http://localhost/RegressionToolWeb/MathService.svc

 

sladapter
Software Engineer
Aprimo, Inc

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

sladapter

Loading...
Joined on 03-05-2008
Indiana, US
Posts 2,164
06-25-2008 3:13 PM
Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

 

The XML page cannot be displayed

Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.


A name was started with an invalid character. Error processing resource 'http://localhost/RegressionToolWeb/MathService.svc...

<%@ ServiceHost Language="C#" Debug="true" Service="MathService" CodeBehind="~/App_Code/MathService.cs" %>
-^
BlasterX

Loading...
Joined on 06-20-2008
Posts 13
06-25-2008 5:38 PM
Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

I have seen this error before. It's the ASP.net get corrupted for some reason.

try this: use Start/Run to run the following command:

%Windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i

then restart IIS.

 

 



sladapter
Software Engineer
Aprimo, Inc

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

sladapter

Loading...
Joined on 03-05-2008
Indiana, US
Posts 2,164
06-26-2008 9:12 AM
Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

 

sladapter:

I have seen this error before. It's the ASP.net get corrupted for some reason.

try this: use Start/Run to run the following command:

%Windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i

then restart IIS.


 I did this and the install worked without any trouble, then restarted IIS, but it did not fix the problem. I get the exact same error messages as before from both internet explorer when trying to use the service and the svc file if I browse to it.

BlasterX

Loading...
Joined on 06-20-2008
Posts 13
06-26-2008 9:43 AM
Marked as Answer
Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

Read this and see if you can find a fix for that.  That's really not Silverlight issue or web service issue. It's ASP.Net issue. Once you can hit your service from browser, then try your silverlight app.

 http://forums.asp.net/t/887716.aspx

sladapter
Software Engineer
Aprimo, Inc

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

sladapter

Loading...
Joined on 03-05-2008
Indiana, US
Posts 2,164
06-26-2008 3:10 PM
Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

 I solved the problem by moving to IIS 6.0 and adding .svc extensions to mime and script extensions.

 Thanks for all of your help, everyone :)

BlasterX

Loading...
Joined on 06-20-2008
Posts 13
07-09-2008 3:55 PM
Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

 Hi sladapter,

 

I have changed my code based on your input.But my code is working fine in Firefox but throwing error in IE

 

throw new Error("Unhandled Error in Silverlight 2 Application Exception has been thrown by the target of an invocation. at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)\n at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)\n at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)\n at System.Delegate.DynamicInvokeImpl(Object[] args)\n at System.Delegate.DynamicInvoke(Object[] args)\n at System.Windows.Threading.DispatcherOperation.Invoke()");

 

this is the error. pls reply me asap. need to give demo to client. 

 

nithya_raghu143

Loading...
Joined on 07-09-2008
Posts 1
07-09-2008 9:57 PM
Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

Hi, nithya_raghu143,

Please be more specific. What code did you change? I did not see you have any post before this one. I don't quite understand what your problem is.

If you mean the following code:

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);

 Make sure you use the following line:

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

It should be address.AbsoluteUrl instead of address.AbsolutePath. I'm not sure this is the reason it works in Firefox not IE. But you need to use the correct one anyway.

 

 

 

 

 

sladapter
Software Engineer
Aprimo, Inc

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

sladapter

Loading...
Joined on 03-05-2008
Indiana, US
Posts 2,164
08-07-2008 11:45 AM
Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

Hi

I try your solution but in my application I continue to obtain the crash in mode publish from IIS.

There is no  address.AbsoluteUrl method but address.AbsoluteUri ?

Uri address = new Uri(Application.Current.Host.Source, "../Service1.svc"); // this url will work both in dev and after deploy.
ServiceReference1.Service1Client c = new Service1Client("BasicHttpBinding_Service1", address.AbsoluteUri);

Could you provide a sample code ?

this is my ServiceReferences.ClientConfig  does something is missing ? 

configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_Service1" maxBufferSize="65536"
                    maxReceivedMessageSize="65536">
                    <security mode="None" />
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost/Service1.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_Service1" contract="deploy1.ServiceReference1.Service1"
                name="BasicHttpBinding_Service1" />
        </client>
    </system.serviceModel>
</configuration>  

Thanks

Fred 

work2gs

Loading...
Joined on 05-26-2008
Posts 34
08-07-2008 1:00 PM
Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

Where is your Service1.svc ? I saw you use http://localhost/Service1.svc in your ClientConfig file (if that is correct url) which means you put it under your domain root, not your the Web Project. If that is the case, following code won't work:

Uri address = new Uri(Application.Current.Host.Source, "../Service1.svc"); // this url will work both in dev and after deploy.
ServiceReference1.Service1Client c = new Service1Client("BasicHttpBinding_Service1", address.AbsoluteUri);

This code only work when your Service1.svc in under the Web Site that host your Silverlight page. If you put the Service one level above your Web folder. then you need to change the Uri building code accordingly.

In debug mode check address.AbsoluteUri. Using that url in a browser should allow you to access your service. If not, then you need to figure out why.

 

 

 


 

 

sladapter
Software Engineer
Aprimo, Inc

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

sladapter

Loading...
Joined on 03-05-2008
Indiana, US
Posts 2,164
08-12-2008 6:32 PM
Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

I don't know what it looks like from the exterior.  I would like some feedback on it

http://gearworld.dyndns.org:8082/devpreview

between 6:00am and 9:00pm EST. Check your SECURITY ZONE since this can prevent you to see the site

if you see the visitor count in the lower left corner that means it work !

GearWorld

Loading...
Joined on 09-13-2007
Posts 307
08-12-2008 6:46 PM
Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

No really it work only if I do F5 or CTRL-F5 in VS 2008 but as soon as I start IE7 outside VS 2008 and go to the web site in localhost. Pouffff you get what you see when you go to my site mentioned above

I have the Web Site in IIS at the same place where I develop it.
I don't know if this could be an issue ?

 

GearWorld

Loading...
Joined on 09-13-2007
Posts 307
08-13-2008 7:20 AM
Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

I followed step by step the video WCFService and I'm still unable to make it work outside VS2008.

Even tought I tried everything people are saying here about endpoint either by code or by the ServiceReference.ClientConfig
It gives a 404 not found and I'm unable to pin point where because I'm unable to debug when this is happening. AS I said it works in VS 2008 so How can I know if it works in VS and its usualy where you can find a bug by debugging but it works in there but not outside vs ???????

Its a terrible situation.  I just hope I will find help to solve this thing.

I did a Publish Web Site where I'm consuming it by IIS which works great anyway except this famous VisitorService.svc which works ONLY IN VS 2008.............

 

GearWorld

Loading...
Joined on 09-13-2007
Posts 307
08-13-2008 8:28 AM
Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

This is what I get from the office.  A bit different then what I see when running it locally

Http Response problem

GearWorld

Loading...
Joined on 09-13-2007
Posts 307
08-13-2008 7:22 PM
Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

Hello ?,  Is there anybody that could help us find out why WCF doesn'T work outside VS2008 ?

Thanx a lot

 

GearWorld

Loading...
Joined on 09-13-2007
Posts 307
08-14-2008 8:17 AM
Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

 Hi

I am in the same situation as GearWorld, anyone could provide a sample ?

I didn't find how to use WCF outside the vs2008 ????

thanks

Fred 

work2gs

Loading...
Joined on 05-26-2008
Posts 34