Page view counter
Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production Subscribe to this thread
Last post 07-03-2009 3:04 AM by ossc_webapp. 55 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 185
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 185
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,860
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,860
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,860
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,860
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,860
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,860
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,860
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,860
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,860
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,860
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 75
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,860
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 866
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 866
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 866
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 866
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 866
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 75
08-14-2008 9:36 AM
Re: Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

 If this has been covered I apologise, but if you are getting a 404 error in the real world it could be that the service address is getting garbled along the way.  Have you tried creating a custome ServiceHost and factory class such as:

public class CustomServiceHost : ServiceHost
  {
    public CustomServiceHost (Type serviceType, params Uri[] baseAddresses)
      : base(serviceType, baseAddresses)
    { }

    protected override void ApplyConfiguration()
    {
      base.ApplyConfiguration();
    }
  }

 

 public class CustomServiceHostFactory : ServiceHostFactory
  {
    protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
    {
      // Specify the exact URL of your web service
      Uri webServiceAddress = new Uri("http://somedomain.com/service.svc");

      CustomServiceHost webServiceHost = new CustomServiceHost (serviceType, webServiceAddress);
      return webServiceHost;
    }
  }

 Then in the service markup stick factory="CustomServiceHostFactory"

 

This has solved all my 404 errors during deployment to me hosting company. 

 

 

RichardBurns

Loading...
Joined on 08-14-2008
Posts 7
08-14-2008 11:39 AM
Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

GearWorld:

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 ?

Could you show the URL for the endpoint in your ServiceReferences.ClientConfig (if you did not do it in code as I suggested in one of my post)?

 

 

 

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,860
08-14-2008 12:22 PM
Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

work2gs:

 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 

 

There is nothing magical to call WCF outside VS2008. But you need to understand how things are working in every case:

If you are running under VS, your are using Dev Server by default. The Dev Server will dynamically set the Page URL and Service URL with a port number. Check the page URL on your browser, it should be something like http://localhost:PORTNO/YourTestPage.html. So when you add Service Reference to your Silverlight project, the Service URL would be http://localhost:PORTNO/YourService.svc.This url will be added to your ServiceReferences.ClientConfig file. Check that file you should see that.

When you call your web service, the ServiceClient has 5 consturctors,  usually people just use the simplist one which does not take any parameters.

var ws =  YourService.YourServiceClient();

By using this constructor you rely on the setting in the ServiceReferences.ClientConfig file.

When you deploy your web to IIS,  the URL of your Page and Service will change. It no longer has that Port number in the URL. It should be something like http://YourServer/YourSite/YourTestPage.html and http://YourServer/YourSite/YourService.svc.

So you need to change the URL for your service in your ClientConfig file after you deploy your Web Site. Actually you need to do this before your last build, because the ClientConfig file will be packaged into the Xap (if you already deployed your Web site. You can use a WinRar tool to extract the ClientConfig file out of the Xap, modify it, then re-Zip it back to the Xap).

But you might still hit cross-domain issue even you changed URL in the ClientConfig if you did the following:

Service URL: http://YourServerName/YourSite/YourService.svc

Page URL: http://localhost/YourSite/YourTestPage.html.

This is considered a cross-domain call because the domain part of your page URL(localhost) and Service URL(YourServerName) are not the same even they are really pointing to the same place. In this case you need a clientaccesspolicy.xml file in your wwwroot folder. Otherwise you will get 404 error.

One way to avoid all these trouble is to use the 3rd method I posted in this thread: By passing the URL reading from the ClientConfig file. Dynamically build the Service URL and set it in code.

Instead of using the default constructor of the ServiceClient, you pass the EndPointName and Endpoint address in the constructor:

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

var ws = YourService.YourServiceClient("YourEndPointName",  address); 

By passing the EndPointName to the constructor, you still rely on the binding settings in the ClientConfig file. When Microsoft provide more binding options later, you can easily change the binding in the Config file. 

This way you do not need to modify your ClientConfig file to change the service URL on each deployed machine, you do not even need the cross-domain policy file because the Service URL and Page URL will always from the same domain. This will work in both Dev server and IIS.

If you still have problem,  you can change default Web Server to IIS while you debugging under VS.  Just right click your Web project and select Web tab. On that tab you can change the Server to use IIS server instead of Dev Server. So you can hit F5 to debug, but the page and service are really running under IIS. 

By the way, this post only applies to calling WebService under the same Web Project(or Web Site). If you are calling a Web Service outside your Web site or a 3rd Party web service, do not use the method suggested in this post.

 

 

 

 

 

 

 

 

 

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,860
08-14-2008 5:23 PM
Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

Hi,

This is exactly what I did :

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

 And believe me this isnt the only thing I did try.  I did try a lot of thigns from videos to Forums threads, from my own things passing by suggestions a bit everywhere, trying google at max, and no, I thing I know everything now about endpoint, clientaccesspolicy.xml and Cross Domain call that even if I do all these things, its still not working so what remains to try for me ?

Is this really a bug ? Are we alone ?, do people succeeded with that ?

I even tried the famous Sniffer called WebDevHelper suggested by no one else then Tim Heuer himself and believe me, it doesn't even look for the clientaccesspolicy file, but it stops at calling my VisitorService.svc which have the endpoing at the very good place and I tried to copy this clientaccesspolixy file EVERYWHERE just to see if it could find it so nah, according to the sniffer, it stops at calling the service and that's it.

It ends up with a very complicated System.ServiceModel error which you can really see by going at http://gearworld.dyndns.org:8082/devpreview
opened from 6:00am to 9:00pm EST Check your SECURITY ZONE since this can prevent you to see the site.

But if only I could even know what to do to PIN POINT the problem.  As you can see its not a fair deal because it works in VS2008 which is the best place to know if something goes wrong but instead, it doesn't work on the LIVE system where its prety hard to debug or see anything.  so actually I'm trying to put in place some traces like the CUSTOM XAML page with the e.Error.STUFF that could reveil the WELL HIDEN problem !!!!

Yes of course it can be as stupid as and endpoint or the policy file missplaced but after all I did how can I know what to try next ????

 

GearWorld

Loading...
Joined on 09-13-2007
Posts 866
08-14-2008 5:31 PM
Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

sladapter:

If you still have problem,  you can change default Web Server to IIS while you debugging under VS.  Just right click your Web project and select Web tab. On that tab you can change the Server to use IIS server instead of Dev Server. So you can hit F5 to debug, but the page and service are really running under IIS.

HUH ?

When I do RIGHT CLICK on my web project, there'S a contextual menu where there's no tab first then if I go in Property page, there's no tab called Web Tab and there's no way to change for IIS but I just have a place where I can choose from USE DEFAULT SERVER or USE CUSTOM SERVER which ask for a URL so sorry but I didnt find it but anyway its not the point for me where I'm at since everything is in place which doesn'T work anyway.  Could it be because of something not working somewhere that prevent all this to work ?  I honestly don't know since I'm unable to see where IS the problem.

I have VS 2008 standard full release

 

GearWorld

Loading...
Joined on 09-13-2007
Posts 866
08-14-2008 5:38 PM
Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

What a lucky day trying to use the Option : Use Custom Server - Web Server in IIS with Windows Vista Home Premium
I didn't pay enough $400 for just developing at home.  Ah well

Lucky

GearWorld

Loading...
Joined on 09-13-2007
Posts 866
08-14-2008 9:55 PM
Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

You can also try to use "attach to process" to debug. On your local machine, turn on the Web share on your Web Project to make it a real web site on IIS (you might have already done this if you create Web site instead of Web project). Then on a browser type your Page URL (http://YourServerName/YourWebSite/YourTestPage.html) to access your page. Then go to your VS, select attach to process to select the browser that has your page open, make sure you select Silverlight Debugger in the Attach To box. Click OK. Set your first break point at the Application_Startup function. Then go back to your browser to refresh your page, now you should hit your first break point. This should allow you debug your Silverlight code while your page is running under IIS.

But your probably can not hit your break point set at your Service code. For debugging Service code you need to attach to ASP.NET process instead of IE.

 

 

 

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,860
08-15-2008 6:57 AM
Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

Here's where it stops when debugging.  Because Now I can get to the error because I did make the service completely outside the web project
See this ProtocolException ? And where it stops ?, I don't have enough knowledge to understand why this is happening.  Now I get this in VS 2008 AND in Live

Debug

GearWorld

Loading...
Joined on 09-13-2007
Posts 866
08-15-2008 9:10 AM
Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

GearWorld:

Because Now I can get to the error because I did make the service completely outside the web project

Where is your Service anyway? Could you show your ServiceReferences.ClientConfig. If your service is outside your Web site, you can not use the code I suggested. That code is not for this case.

GearWorld:

Now I get this in VS 2008 AND in Live

 

You said you only get the error after deploy, now you are getting the error with Dev Server?

Please give the whole information if you want people to help. Or you can post your service calling code and service code (for service code, you only need to post the function signature without real code inside).  But you need to tell us your setup, where the Service code is running, what URL you used to access it.

 

 

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,860
08-15-2008 4:52 PM
Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

Ok here's the information :

1) ONE solution, 3 projects.  Project #1 = Web site ASP.NET project, Project #2 = SilverLight project, Project #3 = WCF service.
2) The Web site is hosted in IIS 7 and consume NO SERVICE AT ALL.
3), The WCF Service project has the clientaccesspolicy.xml at the ROOT, and is running in IIS 7 as a notmal WCF Service

Now for the point #4 here, its a very complicated thing to talk about since I did try so many things.  I'm just going to tell the last one I'm up with right now 

4) The SilverLight Project is consuming the service at the endpoint dynamiclly created (in the code behind of the Silverlight project to point at either the DEV or the LIVE.  Here's the actual code that try to consume the service :

        private void LoadData()
        {
            Uri address = new Uri(Application.Current.Host.Source, "../SilverService.svc");
            Proxy = new GearSite.ProxyCode.SilverServiceClient("BasicHttpBinding_ISilverService", address.AbsoluteUri);
            Proxy.GetVisitorCountCompleted += new EventHandler(Proxy_GetVisitorCountCompleted);
            Proxy.GetVisitorCountAsync();
        }
        void Proxy_GetVisitorCountCompleted(object sender, GearSite.ProxyCode.GetVisitorCountCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                ev.txtErrorMessage.Text = e.Error.Message + "\n\n" + "EndPoint.Address.Uri.AbsoluteUri = " + Proxy.Endpoint.Address.Uri.AbsoluteUri;
                ((ProxyCode.SilverServiceClient)sender).SendEmailAsync(ev.txtErrorMessage.Text);
                ev.Visibility = Visibility.Visible;
            }
            else
            {
                _VisitorCount = ((ProxyCode.Visitor)e.Result[0]).VisitorCount;
                _VisitorCount++;
                lblVisitorCount.Text = "You are visitor number " + _VisitorCount.Value.ToString();
                Proxy.UpdateVisitorCountAsync(_VisitorCount.Value);
                Proxy.CloseAsync();
            }
        }

 Now here's the Service code.  I have nothing to hide here :)

        public List GetVisitorCount()
        {
            List Results = null;

            try
            {
                using (VisitorClassesDataContext VisitorDB = new VisitorClassesDataContext())
                {
                    Results = VisitorDB.Visitors.ToList();
                }
            }
            catch (Exception ex)
            {
                Message = ex.Message;
            }
            return Results;
        }

        void ISilverService.UpdateVisitorCount(int VisitorCount)
        {
            try
            {
                using (VisitorClassesDataContext VisitorDB = new VisitorClassesDataContext())
                {
                    VisitorDB.Visitors.First().VisitorCount = VisitorCount;
                    VisitorDB.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                Message = ex.Message;
            }
        }

Here's the ServiceReference.ClientConfig :

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_ISilverService" maxBufferSize="65536"
                    maxReceivedMessageSize="65536">
                    <security mode="None" />
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://gearworld.dyndns.org:8082/SilverService/SilverService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISilverService"
                contract="GearSite.ProxyCode.ISilverService" name="BasicHttpBinding_ISilverService" />
        </client>
    </system.serviceModel>
</configuration>

 And even a gift here.  how it is setup in IIS :

IIS setup

Here's the solution Explorer  :

Solution Explorer screenshot

GearWorld

Loading...
Joined on 09-13-2007
Posts 866
08-15-2008 5:02 PM
Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

I saw the when we encapsulate code here there are some missing things like above if you look, List GetVisitorCount(...), its List<Visitor> GetVisitorCount(...)  Its not a bug in my code but a bug with the code translator here in this forum :)

GearWorld

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

Here more information for you to salivate on :)

This screenshot is the bigest problem I have since 3 weeks now,  I start to be tired  I'm loosing hope in Web Service with SilverLight

http://pages.videotron.com/gear/bigbigproblem.jpg

In there you can see that the SilverLight report a 404 Not found error which is somewhere in the Asyncronous methods.
While the sniffer shows a 405 verb not allowed.  I did change all the <add verb = "GET, HEAD"....... for <add verb = "*"....... with no success.

I don't know what's going on but I will try to keep hope.

GearWorld

Loading...
Joined on 09-13-2007
Posts 866
08-16-2008 10:49 AM
Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

GearWorld,

Now I understand your problem.

Your WCF service is running in a separate Web from your Page. Then you should not use the following code to access your Service:

 Uri address = new Uri(Application.Current.Host.Source, "../SilverService.svc");   // This won't work
Proxy = new GearSite.ProxyCode.SilverServiceClient("BasicHttpBinding_ISilverService", address.AbsoluteUri);
Proxy.GetVisitorCountCompleted += new EventHandler(Proxy_GetVisitorCountCompleted);
Proxy.GetVisitorCountAsync();

Option1: Move your Service to your Web Project which host your page. So you only have 2 projects in your solution. Then you can use the code above. This should be the easiest.

Option2: Keep your current setting. Do not use the code above. Use default constructor:

 Proxy = new GearSite.ProxyCode.SilverServiceClient();

1) Deploy your WCF Web project first to IIS (on your local machine, just turn on the Web Share on the WCF Web Project folder).  Make sure you can access http://localhost/YourWCFWebSite/SilverService.svc from a browser.

2) Put the clientaccesspolicy.xml file in the inetpub\wwwroot folder. 

3) Then add Service Reference to point to http://localhost/YourWCFWebSite/SilverService.svc.  (no port number)

4) Now you should access this web service from your Silverlight. Test your app. If everything is fine. Test your Web Project that host your page on IIS by using Page url as :http//localhost/YourWeb/YourTestPage.html. They should still work.

4) If everything works, you are ready to deploy it to another server. Just remember you have two Web sites to deploy. One is the Service web site, one is for your page. Deploy the Service site first. Make sure it's working. Remember to copy the clientaccesspolicy.xml to the remote server inetput/wwwroot folder. Then change the URL in your ServiceReference.ClientConfig to point to that service. Test your Siverlight. Build your Silverlight and Web project. Then deploy the Silverlight Web project.

 

 

 


 

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,860
08-16-2008 12:43 PM
Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

sladapter:

  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, thanx, it's great solution!

I spent many hours with this issue, and now it worked!

John Laibach

Loading...
Joined on 08-06-2008
Posts 1
08-16-2008 5:33 PM
Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

Ok I finally found the problem.  Believe me, no one yet talked about this in all the forum.  I searched for it and found nothing about it.

What I don't understand is why this is not made by SilverLight installation or VS2008 installation ???.  This would be sooooooooo much easier for people that doesn't know these technical settings.

 Well, instead of writting everything I did here's a very simple URL which solve all those problems of WCF service not working outside the VS 2008

http://msdn.microsoft.com/en-us/library/ms752252.aspx

Don't thanx me.  I've been looking for that since 3 and a half week, yelling, crying, writting all kind of messages with images and here was
the missing piece of the puzzle.

Enjoy !

Now I can go on with my learning process and make a very interesting LINQ to SQL WCF Service for an eCommerce site :)

 

 

GearWorld

Loading...
Joined on 09-13-2007
Posts 866
08-16-2008 5:41 PM
Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

By the way.  Windows Live Search is your friend.

I invite you to see it working as you can see the visitor count in the lower left corner is visible and working which is the WCF service in action

http://gearworld.dyndns.org:8082/devpreview Opened between 6:00am and 9:00pm EST

Check your SECURITY ZONE which can prevent you to see the site.
Also it would be kind for you to come as I receive emal for visitors which is also in the service :)

GearWorld

Loading...
Joined on 09-13-2007
Posts 866
08-17-2008 1:51 PM
Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

Thanks sladapter 

I successfully found the problem when using the debug mode with IIS instead of DevServer

the user was not existing in my db.

I know, it's a classic...one

Thanks a lot

Fred 


work2gs

Loading...
Joined on 05-26-2008
Posts 75
08-17-2008 7:31 PM
Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

John Laibach:

sladapter:

  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, thanx, it's great solution!

I spent many hours with this issue, and now it worked!

Whoever did this code thank you because DEV and LIVE now can work without having to play with a static endpoint......

 

GearWorld

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

sladapter:

GearWorld,

Now I understand your problem.

Your WCF service is running in a separate Web from your Page. Then you should not use the following code to access your Service:

At first it wasn't.  I was really set up like you're talking bout.  The service IN the web project.  Now I tried so many things.  Yeah anyway now that I found the problem and solved it.  I'm back with the service inside the web project and I like it that way not separated.

I'm an happy man now.  Everything works flowlessly.....

 

GearWorld

Loading...
Joined on 09-13-2007
Posts 866
02-16-2009 11:08 AM
Re: Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

 

simonwalton

Loading...
Joined on 01-29-2009
Posts 2
05-24-2009 9:51 PM
Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production
Awesome. Was struggling with this problem for ages and this helped.
sladapter:
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);
pyrce

Loading...
Joined on 03-19-2008
Posts 4
05-25-2009 6:56 PM
Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production

Sladapter is a kind.  I tell ya that...

GearWorld

Loading...
Joined on 09-13-2007
Posts 866
07-03-2009 3:02 AM
Stick out tongue [:P]Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production
<p></p>
ossc_webapp

Loading...
Joined on 07-02-2009
Posts 861
07-03-2009 3:03 AM
Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production
<p></p>
ossc_webapp

Loading...
Joined on 07-02-2009
Posts 861
07-03-2009 3:04 AM
Re: Re: Re: Deployment of Silverlight App + Silverlight-Enabled WCF Service to Production
<p></p>
ossc_webapp

Loading...
Joined on 07-02-2009
Posts 861
Microsoft Communities