Results 1 to 3 of 3

Thread: calling wcf service from silverlight

  1. #1
    Join Date
    Mar 2009
    Posts
    31

    calling wcf service from silverlight

    I am using silverlight & is a very good application..... Actually i like the way it calls the web service.... So i just wanted to know how to call WCF service from silverlight...???? Please Help....!

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    Re: calling wcf service from silverlight

    To call WCF service operations asynchronously

    Run the ServiceModel Metadata Utility Tool (Svcutil.exe) tool with both the /async and the /tcv:Version35 command options together as shown in the following command.

    Code:
          svcutil /n:http://Microsoft.ServiceModel.Samples,Microsoft.ServiceModel.Samples http://localhost:8000/servicemodelsamples/service/mex /a /tcv:Version35
    This generates, in addition to the synchronous and standard delegate-based asynchronous operations, a WCF client class that contains:

    • Two <operationName>Async operations for use with the event-based asynchronous calling approach. For example:


    Code:
                Public Overloads Sub AddAsync(ByVal n1 As Double, ByVal n2 As Double)
                    Me.AddAsync(n1, n2, Nothing)
                End Sub
    
                Public Overloads Sub AddAsync(ByVal n1 As Double, ByVal n2 As Double, ByVal userState As Object)
                    If (Me.onBeginAddDelegate Is Nothing) Then
                        Me.onBeginAddDelegate = AddressOf Me.OnBeginAdd
                    End If
                    If (Me.onEndAddDelegate Is Nothing) Then
                        Me.onEndAddDelegate = AddressOf Me.OnEndAdd
                    End If
                    If (Me.onAddCompletedDelegate Is Nothing) Then
                        Me.onAddCompletedDelegate = AddressOf Me.OnAddCompleted
                    End If
                    MyBase.InvokeAsync(Me.onBeginAddDelegate, New Object() {n1, n2}, Me.onEndAddDelegate, Me.onAddCompletedDelegate, userState)
                End Sub
    • Operation completed events of the form <operationName>Completed for use with the event-based asynchronous calling approach. For example:


    Code:
    Public Event AddCompleted As System.EventHandler(Of AddCompletedEventArgs)
    • System.EventArgs types for each operation (of the form <operationName>CompletedEventArgs) for use with the event-based asynchronous calling approach. For example:


    Code:
    <System.Diagnostics.DebuggerStepThroughAttribute(),  _
     System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")>  _
    Partial Public Class AddCompletedEventArgs
        Inherits System.ComponentModel.AsyncCompletedEventArgs
        
        Private results() As Object
        
        Public Sub New(ByVal results() As Object, ByVal exception As System.Exception, ByVal cancelled As Boolean, ByVal userState As Object)
            MyBase.New(exception, cancelled, userState)
            Me.results = results
        End Sub
        
        Public ReadOnly Property Result() As Double
            Get
                MyBase.RaiseExceptionIfNecessary
                Return CType(Me.results(0),Double)
            End Get
        End Property
    End Class

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Re: calling wcf service from silverlight

    Inserting the correct Uri in the silverlight application related on the location. Actually the code looks like this :

    Code:
    ServiceClient proxy = GetServiceClient();
    proxy.DoWorkCompleted += proxy_DoWorkCompleted;
    proxy.DoWorkAsync();
    
     
    
    The GetServiceClient() function :
    
    private ServiceClient GetServiceClient()
    {
        Uri uri = new Uri(HtmlPage.Document.DocumentUri, "Service");
        EndpointAddress address = new EndpointAddress(uri);
    
        return new ServiceClient("*", address);
    }

Similar Threads

  1. IIS URL Rewrite and Silverlight calling the https WCF service
    By fanish-war in forum Technology & Internet
    Replies: 5
    Last Post: 21-06-2011, 11:21 AM
  2. Replies: 3
    Last Post: 17-04-2011, 04:55 PM
  3. Replies: 4
    Last Post: 27-10-2010, 01:21 AM
  4. WCF Service in Silverlight
    By SoftWore in forum Technology & Internet
    Replies: 2
    Last Post: 05-08-2010, 03:57 PM
  5. Calling a function from a client Web Service
    By HarshaB in forum Software Development
    Replies: 3
    Last Post: 02-11-2009, 06:46 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,030,015.90560 seconds with 16 queries