2

how to send a custom object from client (jquery) to server (WCF service)

what is the way of passing an object? below is my code and when i see in the firebug this is what i get please see the screen shot: http://img88.imageshack.us/img88/205/54211873.png

var CustomerInfo = {
                Name: '',
                Address: ''
            };

            function buildNewCustomerRequest() {
                var request = {
                    CustomerInfo: CustomerInfo
                };
                request.CustomerInfo.FirstName = $("#Name").val();
                request.CustomerInfo.Address = $("#Address").val(); 

                return request;
            }



     $("#getcustomerobject").click(function (event) {
                    var request = buildNewCustomerRequest();
                     var json = JSON.stringify(request);
                    $.getJSON('http://host/MyService.svc/GetCusto
merObject?CustomerObject=?', { request: json }, function (customer) {

                        //
                    });
                });

 <li>
            <label id="lblFirstName" for="Name">
              First Name :
            </label>
            <input id="Name" name="Name" type="text" maxlength="25" class="required" />  </li>
          <li>
            <label id="lbllastName" for="Address">
              Address :
            </label>
            <input id="Address" name="Address" type="text" maxlength="25" class="required" /><em> </li>
          <li>

here is my WCF service looks like:

public bool GetCustomerObject(string method, Customer customer)
        {
            if (customer.Name == "test")
                return true;
            return false;
        }
Nick Kahn
  • 19,652
  • 91
  • 275
  • 406
  • @chicagland , you should send it like a jsonp object , you can use json library. – kobe Nov 21 '10 at 02:17
  • I had tough time to send as request object, finally i sent all the info as query string objects. – kobe Nov 21 '10 at 02:18
  • @gov, can you show me how did you send through query string object? – Nick Kahn Nov 21 '10 at 02:27
  • @chicagland , access the below page http://www.art.com/gallery/id--c23944/fine-art-prints.htm?ui=F7E7049837DA4C8A91FCB2178C5D7D76 and then mouseover any image , then click in one of the directions.. That is as ajax call to wcf... – kobe Nov 21 '10 at 02:32
  • @ Intially i had some cross browser problems to expose wcf as jsonp Object , then found some link on google where we have to add four classes on wcf layer to expose one of the end points as jsonp ...which will take care of cross domain request issue. But i tried to send all the query string parameters as on request object , but couldn't succeed doing that, Then as i have no time , i just finished the project with querystring parameters. – kobe Nov 21 '10 at 02:34
  • i am on the same page now, i am using same four classes which microsoft talks about `MSDN article “JSON with Padding (AJAX)` on wcf layer to exposes which takes care of cross domain request issue... now i am in the phase where i have to pass the object from client to server (wcf service). – Nick Kahn Nov 21 '10 at 02:39
  • @chicagoland , please let me know if you succeed in passing json object as query string and resolves the same at the WCF level , i can refactor my code. Let me know know if you need anything else. if you want see the querystrings now , you can watch them in .net panel of firebug. – kobe Nov 21 '10 at 02:41
  • sure i will let you know, i will see the querystring in firebug but i still would like to see the code just to get better understanding if you can post here. – Nick Kahn Nov 21 '10 at 02:46
  • @chicagoland , which code do you want, if it is javascript code its there in wishlist.js in that file. you can see the complete code in that file. search for .svc in that file and get there is some method call getserverurl or so..which getsthat – kobe Nov 21 '10 at 02:50

0 Answers0