473,379 Members | 1,222 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Webservice and arrays

I am writing a webservice that has a method which requires an array of a custom object. I am having problems understanding why a few things are occuring

My webservice looks like this

namespace WSTes

/// <summary
/// Summary description for Service1
/// </summary
[WebService(Namespace="http://localhost")
public class Service1 : System.Web.Services.WebServic

[WebMethod
public string Test(DataField[] dfl

return dfl.Length.ToString()

public class DataFiel

public string FieldName=""
public string FieldValue=""

In my client I am accessing the method like this

localhost.Service1 proxy = new localhost.Service1();
localhost.DataField[] df = new localhost.DataField[1]
df[0] = new localhost.DataField()
df[0].FieldName="test"
df[0].FieldValue="user"
proxy.Test(df)

My question is why do I have to assign df[0] to a new instance of DataField when I declared df as a DataField array? If I remove the df[0] = new localhost.DataField(); line I get an object reference not set to an instance of an object error

Maybe I am looking at this all wrong. Is there a better way to pass an array of structured data to a webservice? I switched between using a struct and a class, but both of them act the same way (maybe struct has a bit better performance)

Any help would be greatly appreciated.
Nov 16 '05 #1
1 2389
What you're doing by saying
localhost.DataField[] df = new localhost.DataField[1];
is that yr allocating memory for it. This is not to say you dont have to
intialize each array element. So in essence tho' you've said df[0] is
an Datafield type you havent yet initalized it.
... And there is no better way to do this :(

HTH

Mike wrote: I am writing a webservice that has a method which requires an array of a custom object. I am having problems understanding why a few things are occuring.

My webservice looks like this:

namespace WSTest
{
/// <summary>
/// Summary description for Service1.
/// </summary>
[WebService(Namespace="http://localhost")]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string Test(DataField[] dfl)
{
return dfl.Length.ToString();
}
}

public class DataField
{
public string FieldName="";
public string FieldValue="";
}
}
In my client I am accessing the method like this:

localhost.Service1 proxy = new localhost.Service1();
localhost.DataField[] df = new localhost.DataField[1];
df[0] = new localhost.DataField();
df[0].FieldName="test";
df[0].FieldValue="user";
proxy.Test(df);
My question is why do I have to assign df[0] to a new instance of DataField when I declared df as a DataField array? If I remove the df[0] = new localhost.DataField(); line I get an object reference not set to an instance of an object error.

Maybe I am looking at this all wrong. Is there a better way to pass an array of structured data to a webservice? I switched between using a struct and a class, but both of them act the same way (maybe struct has a bit better performance).

Any help would be greatly appreciated.


--
Regards,
Dilip Krishnan
MCAD, MCSD.net
dilipdotnet at apdiya dot com
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: olafmol | last post by:
Hello, i have a problem using a .NET WSDL Webservice from PHP. Using both the NuSOAP lib for PHP4, and the build-in SOAP lib for PHP5 it seems that the SOAP client cannot pass a variable amount...
3
by: Marco | last post by:
Hello there, We're new to C# and have noticed a strange behaviour which we don't yet understand. We wrote a COM DLL (in VC++ 6.0) which performs some calculation based on some double arrays...
1
by: Mike | last post by:
I am writing a webservice that has a method which requires an array of a custom object. I am having problems understanding why a few things are occuring My webservice looks like this ...
12
by: Jose Fernandez | last post by:
Hello. I'm building a web service and I get this error. NEWS.News.CoverNews(string)': not all code paths return a value This is the WebMethod public SqlDataReader CoverNews(string Sport)...
2
by: Mateusz [PEYN] Adamus | last post by:
Hi I was wondering is there any sense in this idea: Instead of just sending selects to the database server and getting response in the normal way I could make a webservice on the server,...
1
by: Knecke | last post by:
Hi all. I have a problem with returning a custom Result object with webservice. The classes i use is described below (some fields and properties is removed) public class Result { int...
9
by: MMesich | last post by:
I've got an order entry webservice whose WSDL looks like this: <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"...
0
by: Pascal Flückiger | last post by:
Hello I have a tcl-webservice based on tclsoap/tclhttpd. A function returns an array of structs. The problem (someone from csharp.de ng told me): The Soap-functionality of the .Net Framework...
0
by: rudy | last post by:
hello i have written a .net-webservice in c#. the client who accesses my service has a borland-webservice, written in delphi. all text-contents delivered in string-arrays from the borland-ws...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.