473,545 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Webservices, Class Libraries, and Syncronizing Namespaces

I am developing a webservice and a windows application that talk to each
other. They are using a standard VB class library in the background. I am
having problems understanding why I can't sync my namespaces properly.
Example;

My Windows namespace is MyCompany.MyWin dowsSpace
My Webservice namespace is MyCompany.MyWeb Service
My Class Library namespace is MyCompany.MyLib rary

I am using typed objects to send back and forth to my webservice. In my
webservice code-behind page I Have a function that looks like this...

<System.Web.Ser vices.WebServic e(Namespace:="M yCompany.MyLibr ary")_
<System.Web.Ser vices.WebServic eBinding(Confor msTo:=WsiProfil es.BasicProfile 1_1)_
<ToolboxItem(Fa lse)_
Public Class MyWebService
Inherits System.Web.Serv ices.WebService

<WebMethod()_
Public Function HelloWorld(ByVa l MyString As MyCompany.MyLib rary.String)
As MyCompany.MyLib rary.String
Return MyString
End Function

End Class
I register my web reference with my windows application and it asks for a
name. I give it MyWebService as the name. Then, in my code, I use the
following to access the the item and use the webservice...

Protected Friend oWebService As New MyCompany.MyWin dowsSpace.MyWeb Service
Dim oMyString as new MyCompany.MyLib rary.MyString
oMyString.Value = "Hello"
dim oMyStringResult as new MyCompany.MyLib rary.MyString
oMyStringResult = oWebService.Hel loWorld(oMyStri ng)

When I compile the code from above, I get the following error message.
Value of type 'MyCompany.MyLi brary.MyString' cannot be converted to
'MyCompany.MyWe bService.MyStri ng'. on the actual line that calls HelloWorld.

I found a work-around, but I hate doing it, because everytime I make changes
to the web service, I have to go back to the file mentioned below and make
the changes again. I can select to show all files in my web project, then
navigate under web references to the MyWebService's Reference.map.v b file and
change the following code from...
<System.Web.Ser vices.Protocols .SoapDocumentMe thodAttribute(" MyCompany.Libra ry/HelloWorld",
RequestNamespac e:="MyCompany.L ibrary",
ResponseNamespa ce:="MyCompany. Library",
Use:=System.Web .Services.Descr iption.SoapBind ingUse.Literal,
ParameterStyle: =System.Web.Ser vices.Protocols .SoapParameterS tyle.Wrapped) _
Public Function HellowWorld(ByV al oMyString As MyString) As MyString
Dim results() As Object = Me.Invoke("Hell oWorld", New Object()
{oMyString})
Return CType(results(0 ),MyString)
End Function

to...
<System.Web.Ser vices.Protocols .SoapDocumentMe thodAttribute(" MyCompany.Libra ry/HelloWorld",
RequestNamespac e:="MyCompany.L ibrary",
ResponseNamespa ce:="MyCompany. Library",
Use:=System.Web .Services.Descr iption.SoapBind ingUse.Literal,
ParameterStyle: =System.Web.Ser vices.Protocols .SoapParameterS tyle.Wrapped) _
Public Function HellowWorld(ByV al oMyString As
MyCompany.MyLib rary.MyString) As MyCompany.MyLib rary.MyString
Dim results() As Object = Me.Invoke("Hell oWorld", New Object()
{oMyString})
Return CType(results(0 ),MyCompany.MyL ibrary.MyString )
End Function

It forces my object types and allows me to compile it, because they now
match. Does anyone know how to do this the right way? Thanks for your help.
--
Jon Ebersole
Microsoft Certified Solution Developer
Nov 3 '06 #1
1 1968
Hello Jon,

From your description, you've developed an ASP.NET webservice which is
consumed by your winform client application, however, you found that when
generating the webservice client proxy, the classes's namespace doesn't
match the one defined in your webservice project, correct?

As for this issue, it is actually due to XML Webservice's natural design
which is used to connect distributed heterogenous platform/system. Thus,
the client-side webservice consumer(applic ation) should not have sense of
how the server-side webservice is implemented. For example, the client
winform application can add webreference against a certain webservice, and
it will generate client proxy class and other helper classes which will be
used to map the XML WebService's SOAP request/response message and content.
However, client application doesn't need to know how the server webservice
is implemented.(It could be implemented by ASP.NET webservice, or java
webservice or a normal XSLT translator service...)

For your scenario, if you do want to make your webservice's client-side
proxy class use the existing component classes(in a separate class
library), you can consider the following means:

1. Manually modify the auto-generated Reference.cs file. As you have found,
it is a bit inconvenient since the IDE will regenerate the code and
override our modification when updating the proxy. To avoid this, you can
consider use the wsdl.exe to manually create the proxy class externally and
use it in your project:

#Web Services Description Language Tool (Wsdl.exe)
http://msdn2.microsoft.com/en-us/library/7h3ystb6.aspx
2. In .net 2.0, there is a new compilation feature called partial class,
you will find that autogenerated webservice's proxy class is a partial
class. Thus, you can add your modification on the proxy class into another
partial class file (only contains the webservice method that use your own
class)
e.g.
suppose the autogenerated proxy class is as below:
======Reference .cs========
namespace TestClient.Simp leService {
............... .....
[System.CodeDom. Compiler.Genera tedCodeAttribut e("System.Web.S ervices",
"2.0.50727. 42")]
[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
[System.Componen tModel.Designer CategoryAttribu te("code")]

[System.Web.Serv ices.WebService BindingAttribut e(Name="SimpleS erviceSoap",
Namespace="http ://tempuri.org/")]
public partial class SimpleService :
System.Web.Serv ices.Protocols. SoapHttpClientP rotocol {
............... ............... .........
[System.Web.Serv ices.Protocols. SoapDocumentMet hodAttribute(". ...............
............)]
public SimpleClass GetSimpleClassO bject(long id, string name) {
object[] results = this.Invoke("Ge tSimpleClassObj ect", new
object[] {
id,
name});
return ((SimpleClass)( results[0]));
}

}

You can add a new partial class file for the proxy class and add your own
webmethod function, like

#instead of using the "SimpleClas s", I use "MySimpleClass" (defined in
classlibrary)
=======Referenc e.custom.cs==== =============== =====

namespace TestClient.Simp leService
{
............... .....

public partial class SimpleService
{

[System.Web.Serv ices.Protocols. SoapDocumentMet hodAttribute(.. ...............
............... .)]
public MySimpleClass MyGetSimpleClas sObject(long id, string name)
{
object[] results = this.Invoke("Ge tSimpleClassObj ect", new
object[] {
id,
name});
return ((MySimpleClass )(results[0]));
}

}

=============== ========

Thus, the customization code in partial class file won't be modified when
you update proxy class. Here is the reference about partial class in MSDN:

#Partial Class Definitions (C# Programming Guide)
http://msdn2.microsoft.com/en-us/library/wa80x488.aspx

Just some of my opinions on this, hope helps some. If you have any further
questions on this, please feel free to let me know.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

=============== =============== =============== =====

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.
Nov 3 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2775
by: rinku24 | last post by:
We have two C++ libraries (Unix Shared objects) with the same class name and no namespace. Is there any way to load both the libraries and selectivly create the instance of the class from different library? e.g. We have class Process in libABC.so and libXYZ.so. Can I instantiate object of class Process from libABC.so or libXYZ.so by...
1
1117
by: Razzie | last post by:
Hey all, Does it matter what the size of your compiled class libraries is? Since I started developing for my company, I keep adding new classes to my library almost everyday (of course under different and neat namespaces). Is it ok to place everything in one large dll file, or should I split it up? It's not like I have 1000 classes or...
8
1719
by: Allan Ebdrup | last post by:
I just had a discussion with one of my fellow programmers. We have a class for doing some logging and sending an email, it has 5 different scenarioes of loggin that are common enough to share a class and database tables. In the future there might be new scenarioes that require their own custom classes and database tables. Now we want to...
0
1124
by: majiofpersia | last post by:
Hi Everyone and thanks in advance, I am trying to create a webservices which will read a binary file and create another file based on that first one and sends back the new file to the client. The thing is that I don't want to at any time save this file on the server ... I want to do all this in memory if possible. I have two questions: ...
10
3471
by: 4MLA1FN | last post by:
i'm somewhat of a c++ newbie. i'm linking some static libraries into my app. it turns out that two of the libraries (from different suppliers) share a class name; e.g. they both have a class named 'SomeClass'. the compiler/linker is complaining. is there an easy way deal with this so my app can link? thanks.
0
2451
by: =?Utf-8?B?TWljaGFlbA==?= | last post by:
Hello, i have a problem with jagged arrays and a webservice. I try to call a webservice with an array of a class that contains jagged arrays. Here is an example: class MyClass{ string myJaggedArray; string anotherString; }
1
295
by: shapper | last post by:
Hello, I have been working on a project which has the following namespaces: bNET bNET.Blogger bNET.FAQ .... bNET will have a Configuration Class for Web.Config and other common
1
2130
by: linda.chen | last post by:
This is the first project I worked in Visual Studio .NET 2005. I created a webservices by asp.net 2.0. The webservice works correctly in my development environment. When I published the webservice to the default website, even to the same machine (my default website already has a webservices but written in asp.net 1.1), I got the following...
1
4218
by: pantagruel | last post by:
Hi, This is in a windows service in .NET 1.1 I seem to remember reading somewhere that in .NET 1.1 Windows Services are limited in what namespaces they can use - is this so? the only thing that seems to be supported is System.Collections.Specialized.
0
7479
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7411
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7773
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5343
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3468
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1901
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1028
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.