Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,
I developed a wcf service by using windows Azure Cloud service.
Now i need to call that wcf service into my application. I am using Rad center windows phone application. I added wcf service in service reference but not possible to create
a reference in page1.xaml.cs . any suggestions appreciate.

Note: I already goggled i got below link but not useful to my concept.


thanks in advance.
nareshraju
Posted

1 solution

If you've successfully created a service reference in the same project as that code, then it shouldn't be too hard to code it. Getting your config file correct is fiddly, but the code probably goes something like this:


Say my Service Reference is called MyServiceReference and the web service itself is called MyWebService. We'll say that you have a method called Get42 which returns the number 42 as an int.


C#
public Page1()
{
    InitializeComponent();
    this.Loaded += new RoutedEventHandler(Page1_Loaded);
}

void Page1_Loaded(object sender, RoutedEventArgs e)
{
    // Instantiate a web service client
    // Note that the name MyWebService gets the word Client appended
    MyServiceReference.MyWebServiceClient proxy = new MyServiceReference.MyWebServiceClient();
    // Create a handler for the webservice - note it has the word Completed on the end of the web service operation included 
    proxy.Get42Completed += new
        EventHandler<MyServiceReference.Get42CompletedEventArgs>
        (GetDataCompleted);
    // Make the call to the webservice, note it has the word Async appended
    proxy.Get42Async();
}

void Get42Completed(object sender,
    MyServiceReference.Get42CompletedEventArgs e)
{
    // Always check for errors before examining the result
    if(e.Error != null)
    {
        MessageBox.Show(e.Error.ToString());
        return;
    }
    // Read the result
    MessageBox.Show(e.Result.ToString());
}


Here are a few things to watch out for...

Your service reference should be set to allow Async calls, so right click it, and choose "Configure service reference" and check that. Also check that your web service hasn't got its operations marked as static as that makes them invisible to the client.

Hope that helps.

Please mark as the answer if this answers your question.
 
Share this answer
 
v3
Comments
Sandeep Mewara 24-Jun-12 4:37am    
5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900