views:

349

answers:

2

Scenario:

I am using Silverlight 3.0 as client for a web service.

Design:

The server has a class named DeviceInfoService which has the basic functionality of getting the list of devices, getting the properties of devices etc.

When I open an ASP.NET project and try to add a web reference, I can find an option to add a "Web Reference". After I add the web reference this way, I am able to access the DeviceInfoService class by creating it's object and then accessing it's methods.

Web Reference v/s Service Reference:

Coming to Silverlight: when I try to add a service reference, there is no option to add a web reference. Going with Service Reference, everything works fine till WSDL file is downloaded. People say that I can get this option by going back to .NET 2.0, but probably Silverlight won't work in .NET 2.0

The Problem

Now when I try to access the class DeviceInfoService , I am not able to find it. All I get is Interfaces -- DeviceInfoServiceSoap and DeviceInfoServiceSoapChannel. Classes named DeviceInfoServiceSoapClient.

The methods GetHostedDevices and GetDeviceInfo are no longer available. All I get is GetDeviceInfoRequest, GetDeviceInfoRequestBody, GetDeviceInfoResponse and GetDeviceInfoResponseBody.

I googled a lot how to use these four classes, only to find nothing. I want to get those 2 classes directly like in ASP.NET and not using those Request Response type.

+2  A: 

You sound awfully confuse about some concepts.

How about you watch the following Silverlight.Net video and see if that helps? How to Consume WCF and ASP.NET Web Services in Silverlight

JustinAngel
I have started Silverlight, have to consume a web service. The way I used to do traditionally in ASP.NET isn't the same as in Silverlight. This was the reason for the confusion. I was not able to find "Web Reference" when using Silverlight
Manish Sinha
+1  A: 

What is web reference in ASP.NET is equivalent to service reference in Silverlight.

Here's an example of how to use a web service in Silverlight, e.g. the CDYNE Profanity Filter.

Add a new Service Reference to your project, URL is: http://ws.cdyne.com/ProfanityWS/Profanity.asmx?wsdl, leave the name as ServiceReference1.

Use this code behind to call the service (which was implemented to be asynchronous):

public MainPage()
{
    InitializeComponent();

    string badText = "I wonder if the filter will filter this out: shit bad luck";
    ServiceReference1.ProfanitySoapClient client = new ServiceReference1.ProfanitySoapClient();
    client.ProfanityFilterCompleted += new EventHandler<ServiceReference1.ProfanityFilterCompletedEventArgs>(client_ProfanityFilterCompleted);
    client.ProfanityFilterAsync(badText, 0, false);            
}

void client_ProfanityFilterCompleted(object sender, ServiceReference1.ProfanityFilterCompletedEventArgs e)
{
    string cleanText = e.Result.CleanText;  // Web service callback is here
}

And you've got a web service up and running in Silverlight!

Gergely Orosz
Thanks for the answer. I will surely try it out when am at work and come back. This looks like the probable answer. I was also trying to do something the same, but hardly found any tutorials on the internet even after googling.
Manish Sinha
Thanks Gergely, that helped.
Manish Sinha
Gergely I have made some changes in project and the project is halfway. Suddenly I find that the constructor takes infinite amount of time to finish. It actually never finished. What can be the problem.
Manish Sinha
Have you tried debugging the solution to see which call never executes? Is the client_ProfanityFilterCompleted ever called? Without details or code I can't help much.
Gergely Orosz
Gergely, I mean I set a breakpoint on the line `ServiceReference1.ProfanitySoapClient client = new ServiceReference1.ProfanitySoapClient();` when I execute that breakpoint, the browser comes in focus. I checked the code. It does not hit the next breakpoint on the next line. Sort of statement execution flow is lost. There is no such big code right now. I am just clicking on a button to execute this piece of code which you gave.
Manish Sinha