0

I have a silverlight business aplication that gets data from silverlight enabled webservice.

When I run the application in dev environment, it works fine. when i deploy the application and the Asp.net web development server is working, then to the application works fine.

But when I stop the development server, the application can't access a service.

My questions are:

When I deploy a silverlight business application, doesn't the service get deployed and get started.

The endpoint address in my ServiceReferences.Clientconfig file is endpoint address="http://localhost:9702/MyWebservice.scv. Do I need to change this?

The enpoint address in the web.config is blank.

Appreciate your help

4 Answers 4

2

Because the WCF client code is declared as a "partial" class, what I've been doing to this point is creating another c# partial class file to host a GetClient() method on it. You'll notice that the code is taking into account the port that the service is on... in a few of the environments that I've posted or will be posting to, as well as the development environment, the application is not always on port 80.

Namespace Project.Service
{
    public partial class ServiceClient
    {
        public static ServiceClient GetClient()
        {
            return new ServiceClient("CustomBinding_Service",
                new System.ServiceModel.EndpointAddress(new Uri(string.Format("{0}://{1}:{2}/Services/Service.svc",
                    Application.Current.Host.Source.Scheme, Application.Current.Host.Source.Host, Application.Current.Host.Source.Port), UriKind.Absolute)));
        }
    }
}

Hope this helps someone!

1

Yes you are going to want to change your endpoint address. I recommend doing it in the silverlight code when creating the connection to the WCF service. The service itself lives on the web server, whereas the silverlight application lives on the clients computer. If the web server stops, the web service stops but the silverlight app can keep running.

edit:
To do this in code, as long as the path is always in the same domain as the app you can use do like so:

BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None) //Use whatever security you need here  
                {
                    MaxReceivedMessageSize = int.MaxValue,
                    MaxBufferSize = int.MaxValue
                };
Client client = new Client(binding, new EndpointAddress(new Uri(Application.Current.Host.Source, "../MyService.svc")));
3
  • Thanks you. Your exxplaination makes sense. How do I give the address of the IIS location in code?
    – user176687
    Oct 2, 2009 at 4:29
  • Also, When I do it from code, Should I remove the line from ServiceReferences.Client?
    – user176687
    Oct 2, 2009 at 4:30
  • I have edited my answer to include the information on how to connect from the code. Oct 2, 2009 at 20:25
0

Thanks so much for your help. I tried your approach to create the client code but that didn't work. And that's because the problem seems to be somewhere else.

So I installed fiddler to see the traffic.

Fiddler showed that the service was being accessed but the http response code was 302 showing that there was some redirection involved.

The address of my application is like this http:///Silverlightapp/(S(oirppxrwzhlf2a2vbia1ui45))/Default.aspx#/Home and it is hosted on IIS 6.

So I had to employ a workaround by installing the service on machine with IIS7 (and there was no session id involved like in the above url).I still kept the silverlight application hosted on IIS 6.

Anyway, in summary, to anyone who reads the thread, I did the following to troubleshoot and solve issue(temporarily)

  • Changed the end point address in the ServiceReferences.ClientConfig file. When you add the service using discover option in VS, the endpoint address is of the localhost and this must be changed.

  • Registered the service model using ServiceModelReg -i command. (this solved my problem that my applicaiton was only working from development server and not IIS)

-Put the CrossDomain and ClientAccessPolicy files in c:]inetpub\wwwroot folders.

-Used fiddler to look at http response codes. I had to do no configuration in fiddler. Changed the binarymessageEncoding to textMessageEncoding iin the web.config file of the silverlight web project that also hosted the ecf service. I did this becasue adding a silverlight enabled wcf service creates a custom binding configuration in the web.config file by default uses binary encoding. I needed text encoding to see errors in fidder. But this didn't help much becasue I only saw the name of the operation in the Inspector>xml tab in fiddler. This was the same even after my issues was resolved by workaround.

Thanks for the help

-1

Don't do it in code. Otherwise you won't be able to change it later without recompiling the application (when the address will need to change, perhaps years down the road when you've lost the source code :)

Change the address in ServiceReferences.ClientConfig to where the service is actually hosted... e.g. http://example.com/myVdir/MyWebservice.svc

If later on you need to change the address without recompiling: - Open the .xap file (it's just a zip file with a different extension) - Find the .ClientConfig file and change the address - Put it back together as a .zip file and rename to .xap

Also, I can't remember anymore whether the .ClientConfig supports relative addresses (e.g. just "MyWebService.svc"), but if it does it may be a good solution as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.