473,405 Members | 2,338 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,405 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 2391
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.