如何将对象发送到WCF服务? [英] How can I send an object to WCF service?

查看:108
本文介绍了如何将对象发送到WCF服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义类对象作为参数的WCF服务。

I have a WCF service with a custom class object as paramter.

MyClass Call(MyParameter Parameter)



我需要将此对象Parameter传递给此服务,然后继续执行服务中的其余操作。我需要通过JQuery调用此服务。我尝试了JSON对象,但它不起作用,如果它应该工作,我一定做错了。


I need to pass this object, Parameter, to this service and proceed with the rest of the operations in the service. I need to call this service through JQuery. I tried JSON object but it does not work, I must be doing something wrong if it should work, that is.

$.ajax({
            type: "GET",
            url: "http://localhost:56779/Service.svc/web/Call",
            data: { Parameter: parameter },
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            username: "xxxx",
            password: "yyyy",
            processData: true,
            success: function (msg) {
                console.log(msg);
            },
            error: function (e) {
                alert('Error!');
            }
        });



with


with

var parameter = {
            "Parameter": {
                "ID": "A5",
                "Var": "5",
                "Reference": {
                    "ID": "12345678"
                },
                "Order": {
                    "ID": 10,
                    "Category": {
                        "Price": {
                            "Value": "1000"
                        },
                        "Quantity": {
                            "Value": 4
                        },
                        "Date": "1/14/2013"
                    }
                }
            }
        };



我也试过


I also tried

data: JSON.stringify(parameter)



但它不起作用,服务不均匀调用并发生错误。请让我知道如何去做。



我的真正任务是将这样的对象作为SOAP消息发送并获得SOAP响应;如果我不需要通过JSON,那么请直接指导我实现我的目标。



P.S.我想知道如何将对象发送到WCF服务,无论有没有SOAP,所以,当我被引导到我的目标时,我会很高兴有关于这个额外目标的另一个指导。



谢谢!


but it doesn''t work, service is not even called and error occurs. Please let me know how to go about it.

My real task is to send such object as a SOAP message and get a SOAP response; if I don''t need to go through JSON, then please guide me directly to achieve my goal.

P.S. I would want to know how to send objects to WCF service, with or without SOAP so, when I''m guided to my goal, I''d be glad to have another guidance regarding this extra goal.

Thanks!

推荐答案

.ajax({
type: GET
url: http:// localhost:56779 / Service.svc / web / Call
data:{Parameter:parameter},
contentType: application / json; charset = utf-8
dataType: json
用户名: xxxx
密码: yyyy
processData: true
成功: function (msg){
控制台 .log中(MSG);
},
错误:功能(e){
alert(' 错误!');
}
});
.ajax({ type: "GET", url: "http://localhost:56779/Service.svc/web/Call", data: { Parameter: parameter }, contentType: "application/json; charset=utf-8", dataType: "json", username: "xxxx", password: "yyyy", processData: true, success: function (msg) { console.log(msg); }, error: function (e) { alert('Error!'); } });



with


with

var parameter = {
            "Parameter": {
                "ID": "A5",
                "Var": "5",
                "Reference": {
                    "ID": "12345678"
                },
                "Order": {
                    "ID": 10,
                    "Category": {
                        "Price": {
                            "Value": "1000"
                        },
                        "Quantity": {
                            "Value": 4
                        },
                        "Date": "1/14/2013"
                    }
                }
            }
        };



我也试过


I also tried

data: JSON.stringify(parameter)



但它不起作用,服务不均匀调用并发生错误。请让我知道如何去做。



我的真正任务是将这样的对象作为SOAP消息发送并获得SOAP响应;如果我不需要通过JSON,那么请直接指导我实现我的目标。



P.S.我想知道如何将对象发送到WCF服务,无论有没有SOAP,所以,当我被引导到我的目标时,我会很高兴有关于这个额外目标的另一个指导。



谢谢!


but it doesn''t work, service is not even called and error occurs. Please let me know how to go about it.

My real task is to send such object as a SOAP message and get a SOAP response; if I don''t need to go through JSON, then please guide me directly to achieve my goal.

P.S. I would want to know how to send objects to WCF service, with or without SOAP so, when I''m guided to my goal, I''d be glad to have another guidance regarding this extra goal.

Thanks!


试试



http://stackoverflow.com/questions/5348128/consuming-wcf-rest-service-using-jquery-ajax-发布 [在新窗口中打开]



http://pranayamr.blogspot.ca/2011/03/rest.html [ ^ ]



我建议使用POST方法代替GET,通过jQuery将数据传递给服务
try

http://stackoverflow.com/questions/5348128/consuming-wcf-rest-service-using-jquery-ajax-post[Open In New Window]

http://pranayamr.blogspot.ca/2011/03/rest.html[^]

I would recommend POST method instead of GET, to Pass Data to Service through jQuery


这篇关于如何将对象发送到WCF服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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