Page view counter
Web Service
Last post 05-10-2008 2:52 PM by Jim Mangaly. 1 replies.
Sort Posts:
05-10-2008 2:42 PM
Web Service

How to access the Web service Class after, I have in my SL 2.0 project, added references to Web services? 

This is the  Page.xaml.cs:

using SilverlightApplication4.ServiceReference1;

namespace SilverlightApplication4
{
    public partial class Page : UserControl
    {
        public Page ()
        {
            InitializeComponent ();
        }

        private void Button_MouseLeftButtonDown ( object sender, MouseButtonEventArgs e )
        {
             /* If this was aspx page I would do only this:

               WebService ws = new WebService();

               ws.HelloWorld ( "some args" );
        }
    }
}

This is the  WebService.cs:

/// <summary>
/// Summary description for WebService
/// </summary>
[WebService ( Namespace = "http://tempuri.org/" )]
[WebServiceBinding ( ConformsTo = WsiProfiles.BasicProfile1_1 )]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
 [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{

    public WebService ()
    {

        //Uncomment the following line if using designed components
        //InitializeComponent();
    }

    [WebMethod]
    public string HelloWorld ( string x)
    {
        return x;
    }

}

Djangoo

Loading...
Joined on 04-07-2008
Posts 34
05-10-2008 2:52 PM
Marked as Answer
Re: Web Service

Take a look at this post by Tim Heur. It has explanation + sample for accessing data via WCF, asmx and REST. Look at the asmx example since that is your scenario.

All service calls in Silverlight are asynchronous calls. So you will see in that sample that the asmx service call is "wrapped" by WCF-related API's as shown below:

private void AsmxServiceButton_Click(object sender, RoutedEventArgs e)

{

BasicHttpBinding bind = new BasicHttpBinding(); EndpointAddress endpoint = new EndpointAddress("http://localhost:50042/CallingServices_Web/Services/SimpleAsmx.asmx");

AsmxService.SimpleAsmxSoapClient asmx = new CallingServices.AsmxService.SimpleAsmxSoapClient(bind, endpoint);

asmx.HelloWorldWithAsmxCompleted += new EventHandler<CallingServices.AsmxService.HelloWorldWithAsmxCompletedEventArgs>(asmx_HelloWorldWithAsmxCompleted);

asmx.HelloWorldWithAsmxAsync(StringToEmit.Text);

}

void asmx_HelloWorldWithAsmxCompleted(object sender, CallingServices.AsmxService.HelloWorldWithAsmxCompletedEventArgs e)

{

OutputString.Text = string.Format("Output from ASMX: {0}", e.Result.ToString());

}

I would recommend that you check out the whole sample.

Hope this helps,
Jim (http://jimmangaly.blogspot.com/)

Please MARK the replies as answers if they answered your question

http://www.identitymine.com/

Jim Mangaly

Loading...
Joined on 04-21-2008
Kochi, India
Posts 378
Microsoft Communities