473,706 Members | 5,240 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Interface in a Webservice client

I want to use an interface in both the webservice and its client. For
example, the web service implements an interface and then the client cast
that webservice to the inteface. It seems impossible, but I am wondering if
there is a way.

The code below shows how I want it:

/*INTERFACE*/
public interface IEmployee
{
String GetName();
Int32 GetID();

}

/* WEBSERVICE*/
public class Employee : System.Web.Serv ices.WebService ,IEmployee
{
public Employee()
{

//Uncomment the following line if using designed components
//InitializeCompo nent();
}
[WebMethod]
public string GetName()
{
return "Ali";
}
[WebMethod]
public Int32 GetID()
{
return 2333;
}
}

/*Windows Client*/
//but this code is not casting, return null
public IEmployee GetEmployee()
{
//WSEmployee is the webservice reference
return new WSEmployee.Empl oyee() as IEmployee;
}

--
Mike
Nov 30 '05 #1
1 2139
DC
The cast in the client-side code does not work probably because the
webservice proxy does not actually implement IEmployee.

your code like this:
public IEmployee GetEmployee()
{
//WSEmployee is the webservice reference
return new WSEmployee.Empl oyee() as IEmployee;
}

....I am guessing WSEmployee.Empl oyee is the client-side proxy class
generated by wsdl.exe ? Open the .cs file and examine it and you'll see
that you have something like this:

public class Employee : System.Web.Serv ices.Protocols. SoapHttpClientP rotocol
{
public String GetName(...) {...}
public Int32 GetId(...) {...}
}

you must modify the generated (client-side) class to specifically state that
it implements your IEmployee interface. like so:
public class Employee :
System.Web.Serv ices.Protocols. SoapHttpClientP rotocol, IEmployee {
.....
}

Then compile your client and it should work.

-D

"Mike9900" <Mi******@discu ssions.microsof t.com> wrote in message
news:05******** *************** ***********@mic rosoft.com...I want to use an interface in both the webservice and its client. For
example, the web service implements an interface and then the client cast
that webservice to the inteface. It seems impossible, but I am wondering
if
there is a way.

The code below shows how I want it:

/*INTERFACE*/
public interface IEmployee
{
String GetName();
Int32 GetID();

}

/* WEBSERVICE*/
public class Employee : System.Web.Serv ices.WebService ,IEmployee
{
public Employee()
{

//Uncomment the following line if using designed components
//InitializeCompo nent();
}
[WebMethod]
public string GetName()
{
return "Ali";
}
[WebMethod]
public Int32 GetID()
{
return 2333;
}
}

/*Windows Client*/
//but this code is not casting, return null
public IEmployee GetEmployee()
{
//WSEmployee is the webservice reference
return new WSEmployee.Empl oyee() as IEmployee;
}

--
Mike

Nov 30 '05 #2

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

Similar topics

3
2817
by: Tim Burris | last post by:
At the top here i will put a quick description of my problem followed by the long description. This way you want get bored reading! : short version what is the best/recommended way for ASPNET apps to call web services that REQUIRE Client Certificates via SSL long version our company has new requirements, all servers must REQUIRE SSL and Server/client certificates i have setup a test Win2003 server to issue certs so i have a full test...
11
3955
by: Andy | last post by:
Make the story short, I have a VB.NET client interface calling .NET webservice, written in VB.NET as well. I am trying to make the client as thin as possible so I let the webservice part to handle most of the things. Currently I have a class called "Product" sitting my webserivce like the following: Code:
4
11197
by: joe bloggs | last post by:
I am writing a mobile application to interface with a legacy system and I am planning to use web services to communicate with this system. The legacy system receives data through a serial port. What I would like to do is make the serial port accessible via a web service. The web service and the legacy application would be running on the same machine. The mobile application would access the web service via a network connection. It...
1
3087
by: A.M-SG | last post by:
Hi, Can I view/modify SOAP message at the client proxy side without using soap extensions? Thank you,
5
3795
by: AliR | last post by:
Hi Everyone, I have a Visual C++ MFC program, and I am trying to use a webservice written in C#. When I add the webservice to my project using Add Web Reference the sproxy compiler complains about one of the object wanting to extend MarshalByRefObject object, and I get an error SDL1030. I can use the webservice in a C# project just fine but not the C++. Can anyone help me out with this?
3
5081
by: Michael Hoehne | last post by:
Hi, I'm currently facing a problem with a mixed environment using .NET 1.1 and ..NET 2.0 web services. We have a client application (the "client", system 1) running on .NET 2.0/WinXP, calling our web service (The "Web Service Server") running on a separate machine (also .NET 2.0, Win2003 Server, system 2). The web service server (system 2) itself makes calls to methods in the CRM
2
1815
by: Robbert van Geldrop | last post by:
Hello, I have a client that consumes a WebService using a WSE 2.0 sp3 interface. I use a WebProxy as generated by VS.Net, based on a webService URL. Occasionaly when debugging I get an unhandled expection in disassembly code: "Connection was forcidbly closed by remote host" stack trace:
1
1677
by: Kevin S. Goff | last post by:
Hi, all, Hopefully this will make sense: I have 2 classes that implement the same generic interface. public interface IAgingReport<T> { T GetAgingReport(DateTime dAsOfDate); }
1
1866
by: oldVB3r | last post by:
I would like to create a set of web services that share a common set of types (classes, structures, enums). I know I can create a VS 2005 web service based on the Interface statement to contain these common types. The problem is that I cannot determine how to create the implementation web services in a way that I can cast the common types between proxy object parameters in a client app. Please check the snippets of my code: 'Interface...
0
8695
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9285
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9155
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9049
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8989
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7901
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6614
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5938
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4708
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.