Как вызвать две службы WCF в моем приложении silverlight? - PullRequest
0 голосов
/ 25 февраля 2011

У меня есть две службы WCF:

  1. abc.svc
  2. xyz.svc

Я успешно добавил их в свое приложение Silverlight.

Я звоню в службы WCF, как показано ниже:

private void LoadData(DateTime dt1, DateTime dt2, string str)

{

----

private int requestId = 0;

----

 Uri service = new Uri(Application.Current.Host.Source, "../ALBLSalesDataService.svc");      Uri service2 = new Uri(Application.Current.Host.Source, "../ALBLTargetDataService.svc");      ALBLSalesDataServiceClient oSoapClient = new ALBLSalesDataServiceClient("CustomBinding_ALBLSalesDataService", service.AbsoluteUri);      ALBLTargetDataServiceClient oSoapClient2 = new ALBLTargetDataServiceClient("CustomBinding_ALBLTargetDataService", service2.AbsoluteUri);
 Uri service = new Uri(Application.Current.Host.Source, "../abc.svc");

      Uri service2 = new Uri(Application.Current.Host.Source, "../xyz.svc");

      abcClient oSoapClient = new abcClient("CustomBinding_abc", service.AbsoluteUri);

     xyzClient oSoapClient2 = new xyzClient("CustomBinding_xyz", service2.AbsoluteUri);




oSoapClient.GetDataCompleted += oSoapClient_GetDataCompleted;

        oSoapClient.GetDataAsync(new DateRange(dt1,dt2), new name(str), ++requestId);



        oSoapClient2.GetDashboardTargetCompleted += (oSoapClient2_GetDashboardTargetCompleted);

        oSoapClient2.GetDashboardTargetAsync(new DateRangee(dt1,dt2), new name(str), ++requestId);




}

Я реализовал свои методы, но я не получаю никаких данных.

Я новичок в WCF и Silverlight. Можем ли мы вызвать две службы WCF, как показано в приведенном выше коде?

1 Ответ

0 голосов
/ 25 февраля 2011

Cody

Нет причин, по которым вы не можете использовать более одной услуги одновременно. Используйте этот код в качестве руководства.

private void Button_Click(object sender, RoutedEventArgs e)
    {
        DateTime dt1 = DateTime.Now;
        DateTime dt2 = DateTime.Now;
        string str;

        // setup of Cody's oSoapClient2 code omitted
        // ....
        // setup auth service client
        AuthenticationServiceClient client = new AuthenticationServiceClient();

        // setup oSoapClient2 and client "completed" event handlers
        oSoapClient2.GetDashboardTargetCompleted += (oSoapClient2_GetDashboardTargetCompleted);
        client.LoginCompleted += new EventHandler<LoginCompletedEventArgs>(client_LoginCompleted);

        // call each service asyncronusly
        client.LoginAsync("username", "password", "", true, null);
        oSoapClient2.GetDashboardTargetAsync(new DateRangee(dt1,dt2), new name(str), ++requestId)
    }

    void oSoapClient2_GetDashboardTargetCompleted(object sender, LoginCompletedEventArgs e)
    {
       // Do something when oServiceClient2 GetDashboardTarget call completes
       if (e.Result != null)
       {
          // Do Something
       }
    }

    void client_LoginCompleted(object sender, LoginCompletedEventArgs e)
    {
        // do something when client Login service completes
        if (e.Error != null)
        {
            ErrorWindow eWindow = new ErrorWindow("Login Failed", "Error: " + e.Error);
            eWindow.Show();
            return;
        }

        if (e.Result == false)
        {
            ErrorWindow eWindow = new ErrorWindow("Login Failed", "Error: Bad Username/Password combination.");
            eWindow.Show();
            return;
        }

        // Login was successful
        SuccessWindow success = new PopupWindow("Login Successful");
        success.Show();
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...