Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WCF jQuery JSON
I have a WCF service with a custom class object as paramter.
MyClass Call(MyParameter Parameter)
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
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)
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!
Posted 13-Jan-13 23:41pm
Comments
Umais ASGHAR at 14-Jan-13 4:49am
   
This service is being used by a windows form application as well and the return object is also a custom class object.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Umais ASGHAR at 15-Jan-13 3:59am
   
a problem arises, I was using wsHttpBinding at one endpoint (which was used by the windows application) and had to use webHttpBinding for web client. The problem is, there's no security in webHttpBinding and the service is called with or without username-password parameters, which is not acceptable.
 
P.S. I have a custom username-password authentication module for this service.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 5,130
1 DamithSL 4,237
2 Maciej Los 3,700
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,846


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 15 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100