473,394 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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.MyWindowsSpace
My Webservice namespace is MyCompany.MyWebService
My Class Library namespace is MyCompany.MyLibrary

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.Services.WebService(Namespace:="MyComp any.MyLibrary")_
<System.Web.Services.WebServiceBinding(ConformsTo: =WsiProfiles.BasicProfile1_1)_
<ToolboxItem(False)_
Public Class MyWebService
Inherits System.Web.Services.WebService

<WebMethod()_
Public Function HelloWorld(ByVal MyString As MyCompany.MyLibrary.String)
As MyCompany.MyLibrary.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.MyWindowsSpace.MyWebService
Dim oMyString as new MyCompany.MyLibrary.MyString
oMyString.Value = "Hello"
dim oMyStringResult as new MyCompany.MyLibrary.MyString
oMyStringResult = oWebService.HelloWorld(oMyString)

When I compile the code from above, I get the following error message.
Value of type 'MyCompany.MyLibrary.MyString' cannot be converted to
'MyCompany.MyWebService.MyString'. 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.vb file and
change the following code from...
<System.Web.Services.Protocols.SoapDocumentMethodA ttribute("MyCompany.Library/HelloWorld",
RequestNamespace:="MyCompany.Library",
ResponseNamespace:="MyCompany.Library",
Use:=System.Web.Services.Description.SoapBindingUs e.Literal,
ParameterStyle:=System.Web.Services.Protocols.Soap ParameterStyle.Wrapped) _
Public Function HellowWorld(ByVal oMyString As MyString) As MyString
Dim results() As Object = Me.Invoke("HelloWorld", New Object()
{oMyString})
Return CType(results(0),MyString)
End Function

to...
<System.Web.Services.Protocols.SoapDocumentMethodA ttribute("MyCompany.Library/HelloWorld",
RequestNamespace:="MyCompany.Library",
ResponseNamespace:="MyCompany.Library",
Use:=System.Web.Services.Description.SoapBindingUs e.Literal,
ParameterStyle:=System.Web.Services.Protocols.Soap ParameterStyle.Wrapped) _
Public Function HellowWorld(ByVal oMyString As
MyCompany.MyLibrary.MyString) As MyCompany.MyLibrary.MyString
Dim results() As Object = Me.Invoke("HelloWorld", New Object()
{oMyString})
Return CType(results(0),MyCompany.MyLibrary.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 1959
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(application) 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.SimpleService {
....................
[System.CodeDom.Compiler.GeneratedCodeAttribute("Sy stem.Web.Services",
"2.0.50727.42")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("c ode")]

[System.Web.Services.WebServiceBindingAttribute(Nam e="SimpleServiceSoap",
Namespace="http://tempuri.org/")]
public partial class SimpleService :
System.Web.Services.Protocols.SoapHttpClientProtoc ol {
.......................................
[System.Web.Services.Protocols.SoapDocumentMethodAt tribute("................
............)]
public SimpleClass GetSimpleClassObject(long id, string name) {
object[] results = this.Invoke("GetSimpleClassObject", 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 "SimpleClass", I use "MySimpleClass"(defined in
classlibrary)
=======Reference.custom.cs========================

namespace TestClient.SimpleService
{
....................

public partial class SimpleService
{

[System.Web.Services.Protocols.SoapDocumentMethodAt tribute(.................
................)]
public MySimpleClass MyGetSimpleClassObject(long id, string name)
{
object[] results = this.Invoke("GetSimpleClassObject", 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
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...
1
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...
8
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...
0
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. ...
10
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...
0
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...
1
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
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...
1
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 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.