Custom object as input parameter

A

Arcadius A.

Hello!
I'm implementing a simple .NET(C#) web service.
The experiment is to pass custom object or complex data type as the
input parameter to my web service.

I have created a custom class:

[Serializable]
public class Person
{
private int userid;
private string username;
....
public string Username
{
get{ return username;}
set{username=value;}
}
...
}

Now, my web service has a method:

[WebMethod]
public int addUser(Person p)
{
Console.WriteLine("User ID is: "+p.Username);// line#278 !
return 0;
}


At the top of the web service provider class, I have
[System.Xml.Serialization.XmlInclude(typeof(Person))]

I have a .NET GUI client that takes as input a userID, username etc etc.
When I call the addUser() method using the .NET client, it just fails,
complaining about "System.NullReferenceException: Object reference not
set to an instance of an object .....
at addUser(Person p) in ...dp.asmx.cs line 278 "

So, there is something wrong with the web service provider.
I'm sure that my client works fine and send a non-empty object
correctly(I've tested it with a Java implementation of the same service,
It also works fine with other methods in this problememtic .NET
provider, but I'm having troubles with the only method that takes
complex data type.) It seems(?) that the problem is with the web service
provider not being able to unmarshall the sent object.


Any help is welcome.

Arcadius.
 
A

Arcadius A.

Arcadius said:
Hello!
I'm implementing a simple .NET(C#) web service.
The experiment is to pass custom object or complex data type as the
input parameter to my web service.

I figured out the problem.
In the XML file sent to the WS provider, is and element of
<user>...<user> while the service provider was expecting a parameter
<p>...<p>
So the problem was that the called parameter on the client has a
different name than the parameter on the server.

I've just changed the name and it's working.

Thanks.

Arcadius.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top