Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将web服务与Silverlight和WPF结合使用的区别_C#_Wpf_Silverlight_Web Services - Fatal编程技术网

C# 将web服务与Silverlight和WPF结合使用的区别

C# 将web服务与Silverlight和WPF结合使用的区别,c#,wpf,silverlight,web-services,C#,Wpf,Silverlight,Web Services,我在后端Web服务中编写了一个简单的WebMethod。我在WPF应用程序和Silverlight应用程序中都将其用作服务引用 该方法返回一个名为userList的List。这在WPF应用程序中运行良好,我将Service1SoapClient引用为“客户端”。因此,可以通过调用该方法- client.userlist(); //this is the case in WPF app 然而,在Silverlight中,唯一的选择是 client.userListAsync(); //Silve

我在后端Web服务中编写了一个简单的
WebMethod
。我在WPF应用程序和Silverlight应用程序中都将其用作服务引用

该方法返回一个名为
userList
List
。这在WPF应用程序中运行良好,我将
Service1SoapClient
引用为“客户端”。因此,可以通过调用该方法-

client.userlist(); //this is the case in WPF app
然而,在Silverlight中,唯一的选择是

client.userListAsync(); //Silverlight
这在WPF中运行良好,并返回所需的列表,但是Silverlight返回错误-

Error   11  Cannot implicitly convert type 'void' to 'System.Collections.Generic.List<string>'  
错误11无法将类型“void”隐式转换为“System.Collections.Generic.List”
同样与此相关的是,在WPF应用程序中,我在用户列表中添加了richTextBox文本,但在Silverlight
richTextBox1中有效。AppendText
不是有效选项


Silverlight应用程序中的错误在哪里?

Silverlight中的所有web服务调用都是异步的,这意味着您不能在应用程序等待结果返回时执行应用程序块。相反,你告诉Silverlight当它得到结果时该做什么,并让它继续自己的业务,直到那时

Silverlight应用程序的web服务客户端要求您向其传递一个事件处理程序,该处理程序将web方法的返回值作为xxxCompletedEventArgs参数,其中“xxx”是web方法的名称

此页面:告诉您如何设置事件处理程序并使用它处理web服务调用的输出

从页面:

    proxy.GetUserCompleted += new EventHandler<GetUserCompletedEventArgs (proxy_GetUserCompleted);
    proxy.GetUserAsync(1);
    //...
}

//...

void proxy_CountUsersCompleted(object sender, CountUsersCompletedEventArgs e)
{
    if (e.Error != null)
    {
        userCountResult.Text = “Error getting the number of users.”; 
    }
    else
    {
        userCountResult.Text = "Number of users: " + e.Result;
    }
}

proxy.GetUserCompleted+=neweventhandlerSilverlight中的所有web服务调用都是异步的,这意味着您不能在应用程序块等待结果返回时执行它。相反,你告诉Silverlight当它得到结果时该做什么,并让它继续自己的业务,直到那时

Silverlight应用程序的web服务客户端要求您向其传递一个事件处理程序,该处理程序将web方法的返回值作为xxxCompletedEventArgs参数,其中“xxx”是web方法的名称

此页面:告诉您如何设置事件处理程序并使用它处理web服务调用的输出

从页面:

    proxy.GetUserCompleted += new EventHandler<GetUserCompletedEventArgs (proxy_GetUserCompleted);
    proxy.GetUserAsync(1);
    //...
}

//...

void proxy_CountUsersCompleted(object sender, CountUsersCompletedEventArgs e)
{
    if (e.Error != null)
    {
        userCountResult.Text = “Error getting the number of users.”; 
    }
    else
    {
        userCountResult.Text = "Number of users: " + e.Result;
    }
}

proxy.GetUserCompleted+=new eventhandler请确保取消注册您的事件处理程序,否则在下一次使用相同的代理对象执行时,您将在每次执行时再次执行proxy\u countusers completed。回答非常好。这个链接正是我所需要的。非常有效。请确保取消注册事件处理程序,否则在下次执行时,您将使用相同的代理对象执行proxy\u CountUsers,并且在每次执行时再次完成。回答非常好。这个链接正是我所需要的。工作是一种享受。