hello all again
here is what i'm doing,
i've a javascript object, which has key value pairs, and some values are objects themselves.
i'm passing this object to a method in a web service, and i'm able to get the values and also able to see the object (which is a value for some keys),
and also i can read that object (and values) in the callback function in my javascript file.
now my question is - i'm unable to refer to the object's value in .asmx file?
.js object looks like this:
myObj = new customObject(); // customObject is a public class in .cs file with get() and set() methods
myObj['id'] = 1;
myObj['name'] = 'test';
addressObj = new secondCustomObject(); // secondCustomObject is a public class in .cs file with get() and set() methods
addressObj['streeName'] = 'test Street Name';
addressObj['City'] = 'test City';
myObj['address'] = addressObj;
webservice.methodName(myObj, callback);
can anyone guide me how to read the addressObj's values in .asmx file?
Thank you
Sanjay
Hi
Would you please post a demo of your issue?
To troubleshoot this issue, we really need the source code of your webservice to reproduce the problem, so that we can investigate the issue in house. It is not necessary that you send out the complete source of your project. We just need a simplest sample to reproduce the problem. You can remove any confidential information or business logic from it.
Thank you.
Hi
Basically we only need to modify the proxy class that is generated when you add a web reference. I googled and found a nice article about this.
http://ryanfarley.com/blog/archive/2004/05/26/737.aspx
Let me know if you need more info.
Hope this helps.
Thanks!
NOTE:This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.
Hi
Demo:
Page:
<%@. Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<script type="text/javascript">
function HelloWorld()
{
myObj = new person("Andrew","Yin");
myObj["firstName"] = "Jin Yu";
myObj["lastName"] = "Yin";
TestWebService.HelloWorld(myObj,SucceededCallback);
}function person(fName, lName)
{
this.firstName = fName;
this.lastName = lName;
}
function SucceededCallback(result, eventArgs)
{
// Page element to display feedback.
var RsltElem = document.getElementById("ResultId");
RsltElem.value = result;
}
</script><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager runat="server" ID="scriptManagerId">
<Services>
<asp:ServiceReference Path="TestWebService.asmx" />
</Services>
</asp:ScriptManager>
<input id="ResultId" type="text" />
<input id="Button1" type="button" value="button" onclick="javascript: HelloWorld();" /></div>
</form>
</body>
</html>WebService And Class:
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
/// <summary>
/// Summary description for TestWebService
/// </summary>
[ScriptService]
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class TestWebService : System.Web.Services.WebService {public TestWebService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}[WebMethod]
public string HelloWorld(person p) {
return "Hello World, " + p.firstName + " " + p.lastName;
}
}public class person
{
public string firstName = "";
public string lastName = "";
}
Hope this helps.
Thanks
Thank you Yin-Yu for your reply,
I figured that part out, what i'm doing is pass the javascript object with key value pairs and some values are objects [with key value pairs] themselves.
in .asmx file i created custom datatypes for 1. key value pairs and 2. objects. this way i can see my elements [belongs to child objects] in my .asmx file
Thank you
Sanjay
No comments:
Post a Comment