1

Do you know of a good way to pass objects or structs from a winform app to .asmx web service? It seems like this should be really easy in .NET but I'm not seeing it.

Rick Strahl had the same question in 2004 but it looks like what I'm looking for maybe doesn't exist:

http://www.west-wind.com/weblog/posts/2004/Apr/18/Net-Web-Services-and-passing-objects-and-Data

Basically, I just have a simple struct with 10 string or int members. I want to send it to an asmx web service and keep the strong-typing intact. That's it.

I've tried defining the struct on the client and the service. Then I created a DLL with the struct definition in it and included that in both my web service and client. Still had issues b/c the namespaces were different.

I see in posts like the following that it seems people are doing what I'm describing. I just don't know how:

Passing Objects Via Web Service

I could convert the service to WCF if that makes this any easier -- will probably convert it in a few months anyway.

Community
  • 1
  • 1
Trevor
  • 4,620
  • 2
  • 28
  • 37
  • 1
    `b/c namespaces were different` is the crux of your question that we need see the error message and how to reproduce the problem, please edit your question to aid problem diagnosis, thanks! – Jeremy Thompson Apr 25 '12 at 02:23

2 Answers2

1

I don't know why I didn't think of it earlier but Jeremy's response helped out. Instead of creating the definition of the object on the client and on the service, I just made the definition of the struct on the web service public. When I create a struct, I just make sure it's of type global::Webservice.com.mydomain.MyStruct.

Trevor
  • 4,620
  • 2
  • 28
  • 37
0

What have you tried? What errors do you run into? How does your code look like?

However, you might need to mark your class of which you want to pass instances to the web services as [Serializable] (MSDN) like this:

[Serializable] 
public class MyObject
{ 
    // Your properties here
    // Your parameterless constructor
}

Note that everything except a default (parameterless) constructor and the properties will be removed during serialization. This is because when passing objects to a web service you are actually not passing .NET objects but (serialized) data. The corresponding types should be available through the service contract.

Jay
  • 2,141
  • 6
  • 26
  • 37