all groups > dotnet web services > october 2006 >
You're in the

dotnet web services

group:

Consuming a webservice from a class library


Consuming a webservice from a class library Preben Zacho
10/24/2006 12:00:00 AM
dotnet web services: Anyone that has a link or description that simply as possible shows how to
add a web reference to a class library in C# and consuming it?

TIA

PZ

RE: Consuming a webservice from a class library Claus Konrad
10/24/2006 1:16:03 AM
You consume the webservice (generate the proxy) quite traditionally the way
you do in all other aspects.
Just right-click and "Add WebService". VS will produce an app.config file
for you that you should move to the hosting process, but basically there is
no difference.
--
rgds.
/Claus Konrad


[quoted text, click to view]
Re: Consuming a webservice from a class library Claus Konrad
10/24/2006 1:27:01 PM
Sure it is; i've this week performed this very operation.
Do note that by default the namespace of the proxy is called "localhost" or
simular.
So when acceing the proxy towards a WS, you go:

localHost.SomeService proxy = new localhost.SomeService();
proxy.Stuff();

If not - send the project to me (see below).

--
rgds.
/Claus Konrad
http://www.clauskonrad.net



[quoted text, click to view]
Re: Consuming a webservice from a class library Preben Zacho
10/24/2006 1:43:23 PM
If only it was ever so simple :)

If I create a new classlibrary project and add the web reference as usual,
no problem. The webservice name is available at design time.

However, I have an existing solution (windows application) with 8 different
classlibrary projects within. If i add the web reference to the windows
application project, I can access the webservice name at design time. So no
problem with that either. But if I do the exact same process in one of the
classlibraries, the webservice name is NOT available at designtime inside
that project.

So I figure there is some setup that I must do in the solution to make it
work, but have not figured it out yet.

Regards

PZ

[quoted text, click to view]

Re: Consuming a webservice from a class library Preben Zacho
10/25/2006 12:00:03 AM
Hi Claus

I was being ironic. It is easy (normally).

Anyway, I've found the error. If I create a new classlibrary project and add
a web reference to it, it works as it should. I can see the design time WS
object and the webmethods are presented nicely thru the WSDL definition.
However, if I change the namespace of my project to the common namespace of
the solution, the designtime object disappear. Still it exist but I can no
longer access it.

Current solution is therefor to let the namespace remain as it is. Not nice,
but it works.

/PZ


[quoted text, click to view]

Re: Consuming a webservice from a class library Dan B.
1/2/2007 3:39:09 PM

Preben,

I encountered the exact same situation as you, and was puzzled why the webservice wasn't available at design time.

I think it has to do with the Settings.Designer.cs file that is auto generated for the project/class library. It is located under your projects Properties->Settings.settings. It contains the code that reads the app.config for the url to the webservice and places the code under the old namespace. When you change namespaces, the Settings.Designer.cs class doesn't get updated.

Good luck to you, and anyone else having this problem.

-d

EggHeadCafe.com - .NET Developer Portal of Choice
AddThis Social Bookmark Button