By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,040 Members | 1,815 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,040 IT Pros & Developers. It's quick & easy.

Two Classes in a same asmx page.

P: n/a
Hi,

I created a web service application using ASP.

My question is :
When i try to create an extra class in the same asmx file,At the time of
consuming the web service,its showing me only the default class only.
here is my code:

namespace WebService1
{
public class Service1 : System.Web.Services.WebService
{
public Service1()
{
InitializeComponent();
}
private IContainer components = null;

private void InitializeComponent()
{
}

protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}

#endregion

[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
public class newClass : System.Web.Services.WebService
{
public newClass()
{

}

[WebMethod]
public string HelloWorld1()
{
return "Hello World";
}
}
}

***********************************************

In my other ASP apllication
"newclass" is not visible at all.Itz showing only Service1.

What to do if I need other class also.
********************************

Thank you.
Kris.
Apr 20 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"kris" <kr**@discussions.microsoft.comwrote in message
news:20**********************************@microsof t.com...
Hi,

I created a web service application using ASP.

My question is :
When i try to create an extra class in the same asmx file,At the time of
consuming the web service,its showing me only the default class only.
here is my code:

namespace WebService1
{
public class Service1 : System.Web.Services.WebService
{
public Service1()
{
InitializeComponent();
}
private IContainer components = null;

private void InitializeComponent()
{
}

protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}

#endregion

[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
public class newClass : System.Web.Services.WebService
{
public newClass()
{

}

[WebMethod]
public string HelloWorld1()
{
return "Hello World";
}
}
}

***********************************************

In my other ASP apllication
"newclass" is not visible at all.Itz showing only Service1.

What to do if I need other class also.
********************************

Thank you.
Kris.
Are you unable to put the other class into a separate .asmx file? In
general, there should be one class per file.
--
John Saunders [MVP]
Apr 21 '07 #2

P: n/a
Hi John,

I have seen similar kind of code. That is why i am curious. But those
services are written in Java.

I have an other question,,,Can we add a namespace as the web reference.
So that i can use all the classes under that.
Apr 23 '07 #3

P: n/a
"kris" <kr**@discussions.microsoft.comwrote in message
news:F8**********************************@microsof t.com...
Hi John,

I have seen similar kind of code. That is why i am curious. But those
services are written in Java.

I have an other question,,,Can we add a namespace as the web reference.
So that i can use all the classes under that.
No. You can only add a web reference to a WSDL file, either directly or
indirectly.

John
Apr 23 '07 #4

P: n/a
Hi John,

I have these questions :

1)How to convert .cs file to wsdl file and viceversa.
2)Why two classes are not allowed in single asmx file?(As asked in the
example)

Thank you.
Apr 23 '07 #5

P: n/a
"kris" <kr**@discussions.microsoft.comwrote in message
news:F8**********************************@microsof t.com...
Hi John,

I have seen similar kind of code. That is why i am curious. But those
services are written in Java.

I have an other question,,,Can we add a namespace as the web reference.
So that i can use all the classes under that.
No. You can only add a web reference to a WSDL file, either directly or
indirectly.

John
Apr 24 '07 #6

P: n/a
"kris" <kr**@discussions.microsoft.comwrote in message
news:25**********************************@microsof t.com...
Hi John,

I have these questions :

1)How to convert .cs file to wsdl file and viceversa.
2)Why two classes are not allowed in single asmx file?(As asked in the
example)
Kris,

1) If you're referring to your .asmx.cs file, then .NET will use reflection
on your [WebService] classes within that file and will produce a WSDL for
you when someone makes a request for <yourFile>.asmx?WSDL
2) Two classes are _allowed_, I just happen to think they're not a good
idea. In general, for web services or any other kind of class, I think it
best to keep one class per file. It's easier to find them that way!
--

John Saunders [MVP]
Apr 24 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.