473,378 Members | 1,343 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,378 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 2388
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.