WebService

  • Thread starter Thread starter Zürcher See
  • Start date Start date
Z

Zürcher See

I have to write a program to pass data through a web service, Ill use two
strongly typed dataset enbedded in a library class, a "request" and an
"answer" dataset.
I've wrote the program and the web service and placed in the references the
library class, but when I tried to use the web method, I coudn't pass the
dataset of the library class. The web service has changed the reference to
the dataset and I have to reference the dataset of the web service!?! But
why if they are the same datasets? Why the web service has to change the
namespace of my library class?

Web service:

public class Test: System.Web.Services.WebService{

public Test(){}
[WebMethod]

public LibraryClass.Answer SetDataSet(LibraryClass.Request dsRequest)

{

LibraryClass.Answer dsAnswer=new LibreryClass.Answer();

....

return dsAnswer;

}

}

When I try in the program to use the web service method SetDataSet, it gives
me the following info:

"test" is the reference name of the web service

test.Test wsTest=new test.Test();

"test.Answer Test.SetDataSet(test.Request dsRequest)"

Why it changes the reference of LibraryClass to "test"?
 
This happens because the relatively simple-minded WSDL.exe utility creates a
new wrapper class named test.LibraryClass, and *that* is what's returned
from the web service proxy. You can see this yourself if you look at the
proxy code generated by Visual Studio. Follow thse steps:

- Open Solution Explorer, and click the Show All Files icon (it looks like
a set of documents - hover to get the tooltip)
- Expand your web reference through the reference.map subtree - there will
be a C# file down there somewhere.
- If you open the file, you'll see the definition of text.LibraryClass.

So there you are. Assuming you want to reference, the One True LibraryClass
assembly, and not the ersatz shadow given to you by Visual Studio, you can
modify the source in this C# file, but be aware that:
- You'll need to have the type broken out into an assembly that is shared
by client and web service.
- This file will be overwritten when you update the web service reference.
You can mitigate the pain by saving the modified version of the file, and
using a diff tool after updates.
- You'll open up a possibility of type versioning issues when the client
and server versions of the assembly drift. If types have different XML
serialization semantics, you'll have unexpected results.

Here's what you can do:
- Remove the definition of the test.ClassLibrary type from the reference C#
file.
- Optionally, add a using statement to this C# file to include the
namespace.
- Add a reference to the assembly that defines the ClassLibrary type

Recompile - it should work. Or at least it might work, if I didn't leave any
steps out ;) Seriously, we have a few applications that use a similar
approach, except that we generally have a client-side assembly that rolls-up
all of the client-side proxies. The problem is that it add a bit more work
to the management of your client-side code, although it does make it
possible to share types among multiple endpoints.

--
Mickey Williams
Author, "Microsoft Visual C# .NET Core Reference", MS Press
www.servergeek.com


Zürcher See said:
I have to write a program to pass data through a web service, Ill use two
strongly typed dataset enbedded in a library class, a "request" and an
"answer" dataset.
I've wrote the program and the web service and placed in the references the
library class, but when I tried to use the web method, I coudn't pass the
dataset of the library class. The web service has changed the reference to
the dataset and I have to reference the dataset of the web service!?! But
why if they are the same datasets? Why the web service has to change the
namespace of my library class?

Web service:

public class Test: System.Web.Services.WebService{

public Test(){}
[WebMethod]

public LibraryClass.Answer SetDataSet(LibraryClass.Request dsRequest)

{

LibraryClass.Answer dsAnswer=new LibreryClass.Answer();

....

return dsAnswer;

}

}

When I try in the program to use the web service method SetDataSet, it gives
me the following info:

"test" is the reference name of the web service

test.Test wsTest=new test.Test();

"test.Answer Test.SetDataSet(test.Request dsRequest)"

Why it changes the reference of LibraryClass to "test"?
 
Thanks, but I've found another problem, and a solution for both. The data I
have to send are too big, more the 10 MB, yes you can change the
configuration of the webserver ....
Because the dataset of the webservice and LibraryClass are the same, I copy
the rows from one to the other

WebServiceDataSet.Request.Rows.Add(row.ItemsArray());

I copy about 2 MB, and I post it, get the answer, copy the rows from the
webservice answer table to my libraryclass dataset table, and so on till i
sended all the data.

I know, it's not very "clean", but so I lost two problems in one.

Thank's for the help anyway

Mickey Williams said:
This happens because the relatively simple-minded WSDL.exe utility creates a
new wrapper class named test.LibraryClass, and *that* is what's returned
from the web service proxy. You can see this yourself if you look at the
proxy code generated by Visual Studio. Follow thse steps:

- Open Solution Explorer, and click the Show All Files icon (it looks like
a set of documents - hover to get the tooltip)
- Expand your web reference through the reference.map subtree - there will
be a C# file down there somewhere.
- If you open the file, you'll see the definition of text.LibraryClass.

So there you are. Assuming you want to reference, the One True LibraryClass
assembly, and not the ersatz shadow given to you by Visual Studio, you can
modify the source in this C# file, but be aware that:
- You'll need to have the type broken out into an assembly that is shared
by client and web service.
- This file will be overwritten when you update the web service reference.
You can mitigate the pain by saving the modified version of the file, and
using a diff tool after updates.
- You'll open up a possibility of type versioning issues when the client
and server versions of the assembly drift. If types have different XML
serialization semantics, you'll have unexpected results.

Here's what you can do:
- Remove the definition of the test.ClassLibrary type from the reference C#
file.
- Optionally, add a using statement to this C# file to include the
namespace.
- Add a reference to the assembly that defines the ClassLibrary type

Recompile - it should work. Or at least it might work, if I didn't leave any
steps out ;) Seriously, we have a few applications that use a similar
approach, except that we generally have a client-side assembly that rolls-up
all of the client-side proxies. The problem is that it add a bit more work
to the management of your client-side code, although it does make it
possible to share types among multiple endpoints.

--
Mickey Williams
Author, "Microsoft Visual C# .NET Core Reference", MS Press
www.servergeek.com


Zürcher See said:
I have to write a program to pass data through a web service, Ill use two
strongly typed dataset enbedded in a library class, a "request" and an
"answer" dataset.
I've wrote the program and the web service and placed in the references the
library class, but when I tried to use the web method, I coudn't pass the
dataset of the library class. The web service has changed the reference to
the dataset and I have to reference the dataset of the web service!?! But
why if they are the same datasets? Why the web service has to change the
namespace of my library class?

Web service:

public class Test: System.Web.Services.WebService{

public Test(){}
[WebMethod]

public LibraryClass.Answer SetDataSet(LibraryClass.Request dsRequest)

{

LibraryClass.Answer dsAnswer=new LibreryClass.Answer();

....

return dsAnswer;

}

}

When I try in the program to use the web service method SetDataSet, it gives
me the following info:

"test" is the reference name of the web service

test.Test wsTest=new test.Test();

"test.Answer Test.SetDataSet(test.Request dsRequest)"

Why it changes the reference of LibraryClass to "test"?
 
Back
Top