有关网络服务调用的问题 [英] Question regarding webservice calls

查看:80
本文介绍了有关网络服务调用的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.

我看过很多教程,这些教程讨论了对Web服务的jquery JSON调用.
基本上,其中许多建议您像这样进行网络服务调用:

Hi.

I´ve seen many tutorials that talks about jquery JSON calls to a webservice.
Basically many of them suggest that you make a webservice call like this:

$.ajax({
        type: "POST",
        data: "{''SomeText'': " + $("#textbox").val() + "}",
        url: "/YourWebService.asmx/MethodName",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: functionToCallWhenSucceed,
        failure: funcitonToCallWhenFailed
});



但是,当我可以使用以下更简单的代码调用Web服务时,为什么要这样做:



But why do I want to do that, when I can call the webservice with more simple code like this:

Namespace.WebserviceName.TheMethod(Variable1, Variable2, functionToCallWhenSucceed, funcitonToCallWhenFailed);



我知道第一个选项是POST调用,但这有什么区别?从.net 4.0 Web服务传输的数据是否仍未在JSON中序列化?

希望您能帮助我了解这些与Web服务通信的方式之间的区别.

非常感谢您,并致以诚挚的问候,
Lars



I know that the first option is a POST call, but what difference does it make? And isnt the data transferred from the .net 4.0 webservice not serialized in JSON anyway?

I hope you can help me understand the difference between these ways of communicating with a webservice.

Thanks alot, and kind regards,
Lars

推荐答案

.ajax({ 输入:"POST", 数据:"{''SomeText":"+
.ajax({ type: "POST", data: "{''SomeText'': " +


(#textbox").val()+}", 网址:"/YourWebService.asmx/MethodName", contentType:"application/json; charset = utf-8", dataType:"json", 成功:functionToCallWhenSucceed, 失败:funcitonToCallWhenFailed });
("#textbox").val() + "}", url: "/YourWebService.asmx/MethodName", contentType: "application/json; charset=utf-8", dataType: "json", success: functionToCallWhenSucceed, failure: funcitonToCallWhenFailed });



但是,当我可以使用以下更简单的代码调用Web服务时,为什么要这样做:



But why do I want to do that, when I can call the webservice with more simple code like this:

Namespace.WebserviceName.TheMethod(Variable1, Variable2, functionToCallWhenSucceed, funcitonToCallWhenFailed);



我知道第一个选项是POST调用,但这有什么区别?从.net 4.0 Web服务传输的数据是否仍未在JSON中序列化?

希望您能帮助我了解这些与Web服务通信的方式之间的区别.

非常感谢您,并致以诚挚的问候,
Lars



I know that the first option is a POST call, but what difference does it make? And isnt the data transferred from the .net 4.0 webservice not serialized in JSON anyway?

I hope you can help me understand the difference between these ways of communicating with a webservice.

Thanks alot, and kind regards,
Lars


但是当我可以使用更简单的代码调用Web服务时,为什么要这么做呢?"
您说得很对:第二个代码更简单,但是第一个调用可以从浏览器进行(它只是Javascript).这意味着您可以直接从HTML页面使用Web服务.第一种方法需要从Web服务器调用.可以启用AJAX启用Web服务,但这需要下载大量JavaScript(〜1700k!),以使大多数最终用户不希望调用此方法.为此,jQuery变得更轻松.

从.net 4.0 Web服务传输的数据是否仍未在JSON中序列化?
并非总是取决于您的设置,它可以通过称为SOAP的协议进行传输,这更为冗长(一种特殊的XML Schema),但它确实具有更强的类型. SOAP vs JSON是一个神圣的话题,但如果使用正确,则每个都有其应有的地位.您必须更改序列化器以返回JSON,默认序列化为XML.
"But why do I want to do that, when I can call the webservice with more simple code like this?"
You are quite right: the second code is simpler, but the first call can be made from the browser (it is just Javascript). This means you can consume web services direct from an HTML page. The first method would need to be called from the web server. You can AJAX enable the webservice, but this requires the download of a lot of JavaScript (~1700k!) to make the call most end users don''t want to do this, the jquery is lighter.

And isnt the data transferred from the .net 4.0 webservice not serialized in JSON anyway?
Not always it depends on your set-up, it can be transferred via a protocol called SOAP, this is much more verbose (a specialised XML Schema) but it does have stronger typing. SOAP vs JSON is a holy-war topic, but each has its place if used correctly. You have to change the serializer to return JSON , the default serialisation is XML.


这篇关于有关网络服务调用的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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