# .NET and More > Silverlight >  Consuming a web service problem -RESOLVED-

## gtilles

This code which works in VS2005 as a ASP.net Web Client and vb.net app does not work in 2010 Silverlight app.
VS2010 Silverlight says that CourseOutline is undefined.
Furthermore I seem to have new methods such as GetRequest, GetRequestBody, GetResponse, GetResponseBody, and
GetCompletedEventsArgs.
Some of the properties are still there but not CourseOutline. Has it been buried within another property?
Is consuming a service handled differently in Silverlight?
I have the Web Service added as a service reference. Any help would be appreciated. Thanks.

        Dim myService As CourseOutline = Nothing
        myService = New CourseOutline
        Dim myCourseInfo() As CourseVersionInfo = Nothing
        Try
            myCourseInfo = myService.GetActiveCourses(20137, "ART")
        Catch ex As Exception

        End Try

----------


## gep13

Hello,

Silverlight is a subset of the .Net Framework, as a result, some things are available to it.

For instance, System.Data.DataSet does not exist within Silverlight.

It is possible that you are using things within the Web Service that works happily within ASP.Net, but that is not supported in Silverlight.

It this web service currently public that we could take a look at it?  If not, is it possible for your to share the method declarations for your Web Service?

Gary

----------


## gtilles

The method below is the one I am referring.
As you can see I'm just filling an array made from a custom structure. 
 <WebMethod()> _
    Public Function GetActiveCourses(ByVal pTermID As String, ByVal pDiscipline As String) As CourseVersionInfo()
        Dim myStructArray As CourseVersionInfo() = Nothing

        Dim myCourseVersions As CourseVersions = Nothing
        myCourseVersions = New CourseVersions

        myCourseVersions.GetActiveVersions(pTermID, pDiscipline, 0)


        Dim myCourseCount As Integer = 0
        ReDim myStructArray(myCourseVersions.Count - 1)
        Dim myCourseVersion As CourseVersion = Nothing
        For Each myCourseVersion In myCourseVersions
            myStructArray(myCourseCount).Department = myCourseVersion.Department
            myStructArray(myCourseCount).Discipline = myCourseVersion.CourseDiscipline
            myStructArray(myCourseCount).CourseID = myCourseVersion.CourseID
            myStructArray(myCourseCount).CourseVersionID = myCourseVersion.CourseVersionID
            myStructArray(myCourseCount).CourseDiscNbr = myCourseVersion.CourseDisciplineNbr
            myStructArray(myCourseCount).CourseKey = myCourseVersion.CourseKey
            myStructArray(myCourseCount).CourseTitle = myCourseVersion.CourseDescLong
            myStructArray(myCourseCount).TermEffective = myCourseVersion.TermEffective
            myStructArray(myCourseCount).TermInactive = myCourseVersion.TermInactive
            myCourseCount += 1

        Next


        myCourseVersion = Nothing
        myCourseVersions = Nothing
        Return myStructArray
    End Function

The service is public but I'd prefer to keep a low profile on it, I'd be happy to PM the URL

----------


## gep13

Could you PM me the details?  I don't see anything immediately wrong with the above.

Gary

----------


## gep13

Hello,

Sorry for the lack of reply on this, only just now getting a chance to look at this.

Are you aware that in Silverlight, you are not "allowed" to do Synchronous Methods, since this has the potential to lock the UI thread, and this is deemed as "bad practice".  As a result, when you generate a service reference for a Silverlight Application, you will not get a method created called GetActiveCourses, instead you are going to get one called GetActiveCoursesAsync.  These methods are the same, it is just that one uses a synchronous pattern, and the other uses an asynchronous pattern.

I think that this is at the root of your problem.

Hope that helps!

Gary

----------


## gtilles

I do see that now and I have been able to consume the service.
What is still confusing to me is now the function no longer returns a value but I have to rely on the event to fire in order to get my data.
So if I can't return a value from a function then I have to have a private variable  for my class and then set the variable value in the event handler.
This seems to work but am I correct in that Web Services in Silverlight no longer return a value except when the event fires (a different sub all together)?

----------


## gep13

Hello,

Within Silverlight the programming model is different.  You can't just call a function anymore, and immediately get the response.  The method is called Asynchronously, and the response you get back is in the callback method.

Does that make sense?

Gary

----------


## gtilles

Yup, It does now.
I've been coding away in Silverlight with my Web Service for several days and it seems to be working well.
Just took awhile to get used to using the event to handle the result instead of a return value from a single function call.
So far so good. Thanks.

----------


## gep13

Glad to hear that you got it working.

If your question has been answered, can you please remember to go back and mark it as resolved?

Thanks

Gary

----------

