Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a WCF service with a custom class object as paramter.
C#
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.
JavaScript
$.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
JavaScript
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
JavaScript
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
Comments
Umais ASGHAR 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

 
Share this answer
 
Comments
Umais ASGHAR 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900