如何使用html5消费wcf服务而不需要修改它 [英] how to consume wcf service with html5 without modiying it

查看:107
本文介绍了如何使用html5消费wcf服务而不需要修改它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我们有一个MVVM架构的项目,我们依靠wcf服务来返回数据。客户端是银光。现在我们想要保留模型而不修改它,但客户端将纯粹是HTML5并需要ajax来调用service.Is它可能吗?特别是当你知道使用silverlight时我们使用datacontract而在html5中我们需要json,就像我想的那样。换句话说,我们希望与wcf服务具有相同的模型,客户端将是silverlight,html5 ......

并且是否有必要添加属性WebInvoke

 [OperationContract] 
[WebInvoke(方法= POST,BodyStyle = WebMessageBodyStyle.Wrapped,RequestFormat = WebMessageFormat.Json,ResponseFormat = WebMessageFormat.Json)]
VMActeur Authenticate(UserProfile userProfile);

解决方案

您好,



我认为 JQuery [ ^ ]库应该允许你做你想要的。下面是一个小代码片段,展示了如何完成。

 


.ajax( test.html,{
type: < span class =code-string> POST,
cache: false
data:{userId:' some.user@foo.com',userpass:' 2734xdb72348sdbds'},
dataType:' json'
成功: function (data,txtStatus,jqXHR){
// 使用响应的代码
},
错误: function (jqXHR,txtStatus,errThrown){
// 处理错误的代码
}
});



问候,


参考以下文章。



1. 使用jQuery调用WCF服务 [ ^ ]。

2. [JQuery]如何从JQuery调用WCF服务? [ ^ ]

Hi,

We have a project with MVVM architecture and we rely on to wcf service to return data.The client side was a silverlight .Now we want to preserve the Model and not modifying it but the client side will be purely HTML5 and need ajax to call service.Is it possible?especially as y know that with silverlight we works with datacontract and in html5 we need json as i thought. In other word , we want to have the same model with wcf service and the client will be whatever silverlight ,html5...
And Is it necessary to add the attribute WebInvoke

[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat =  WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
VMActeur Authenticate(UserProfile userProfile);

解决方案

Hello,

I think JQuery[^] library should allow you do what you want. Below is a small code snippet showing how it can be done.


.ajax("test.html", { type: "POST", cache: false, data: {userId: 'some.user@foo.com', userpass: '2734xdb72348sdbds'}, dataType: 'json', success: function(data, txtStatus, jqXHR) { // Your code to work with response }, error: function(jqXHR, txtStatus, errThrown) { // Code to deal with the errors } });


Regards,


Refer the below articles.

1. Calling WCF Services using jQuery[^].
2. [JQuery] How to call a WCF service from JQuery ?[^].


这篇关于如何使用html5消费wcf服务而不需要修改它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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