如何使用WCF在Silverlight上进行项目? [英] How make project on silverlight with WCF?

查看:104
本文介绍了如何使用WCF在Silverlight上进行项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!我在Silverlight 4上有一个项目,它看起来像原始的社交网络.我正在通过MVVM-pattern创建此项目.我现在必须使用WCF进行此项目.
我已经为WCF初学者阅读了一些文献,但这对我没有太大帮助.
我正在SomeProject.Web Silverlight WCF服务中创建.当我获得svc文件时,我不知道下一步该怎么做.
例如:
这是方法,我有不同的方法,例如:

Hi! I have a project on Silverlight 4, it looks like primitive social network.I''m creating this project by MVVM-pattern.I have to do this project with WCF right now.
I have read some literature for beginners WCF little bit, but that didn''t help me a lot of.
I''m creating in SomeProject.Web Silverlight WCF-service.When I got svc file i don''t know what i have to do next.
For example:
This is method, I have different methods like this:

public void LoadImage(object param)
{
    bool result = (bool)_loadImage.ShowDialog();
    if (!result)
        return;
    ....
}


这是此方法的命令:


This is command for this method:

public ICommand _LoadImage
{
    get{
        if (loadImage == null)
            loadImage = new Model.DelegateCommand(LoadImage, CanAdd);
        return loadImage;
    }
}


在视图模型中
我的问题:
如何为wcf划分程序?
svc文件中应该包含什么?我与方法有什么关系?请替换为svc或其他内容.请使用mvvm提供一些非常简单的示例,或者只是提供一些广告)
请帮帮我.
谢谢.


In viewmodel
My question:
How I can divide my program for wcf?
What should be in svc file?What I have to do with methods?replace in svc or something else.Please provide some very simple examples with mvvm or just give some advertise)
Please help me.
Thak you.

推荐答案

托马斯,

您需要在.Web项目中添加WCF服务,然后将WCF服务的服务引用提供给SL appl.使用合同向服务中添加方法.需要使用服务时,请创建serviceContext的对象.

BR,
Sagar
Hi Thomas,

You need to add WCF service in .Web project, then give service reference of your WCF Service to your SL appl.Add methods to the Service using contracts. Create object of the serviceContext whenever you need to use the service.

BR,
Sagar


hai thomas,
在解决方案资源管理器中右键单击您的项目->选择添加服务参考

然后会出现一个小窗口,为您提供服务网址


然后将在ur silverlight应用程序中添加一个新文件夹作为服务参考
它包含我们的服务...
现在您需要创建一个代理来调用您的服务

VB
=======

hai thomas,
Right click your project in solution explorer ->Select Add service Reference

then a small window will appear in that give ur service url


then a new folder will be added in ur silverlight apps as Service References
it contain ur service...
now u need to create a proxy to call ur service

VB
=======

Dim proxy As ServiceReference1.Service1Client



其中ServiceReference1是您的ServiceReference名称
//在服务中调用getdata函数

proxy.getdataAsync()
AddHandler proxy.getdataCompleted,AddressOf SomeFunction()

//完成后,调用方法SomeFunction()从您的服务中获取数据



Where ServiceReference1 is ur ServiceReference name
//Call getdata function in service

proxy.getdataAsync()
AddHandler proxy.getdataCompleted, AddressOf SomeFunction()

//on completed call a method SomeFunction() to get data from ur service

Private Sub SomeFunction(ByVal sender As Object, ByVal e As ServiceReference1.get4cCompletedEventArgs)
Dim data as string 
 Data= e.Result
End Sub


这篇关于如何使用WCF在Silverlight上进行项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆