Web服务中的多个类 [英] Multiple class in web service
本文介绍了Web服务中的多个类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好朋友
我想创建一个Web服务,但是我有很多类.我想在单个wsdl中调用所有类.
例如,[假设在此类中实现的Web服务]
Hello friends
I want to create one web service but I have many classes. I want to call all classes in single wsdl.
For example [Assume web service implemented in this class]
namespace User
{
public class MyClass1
{
public string Name(){return "Imrankhan";}
}
}
namespace User
{
public class MyClass2
{
public string Surname(){return "Pathan";}
}
}
我的Asmx文件是User.asmx.
现在,当我在网站中添加Web服务引用时,我想按以下方式进行访问
my Asmx file is User.asmx.
Now when I add webservice reference in website, I want to access as following way
User.MyClass1 c1=new User.MyClass1();
string name = c1.Name();
User.MyClass2 c2=new User.MyClass2();
string surname = c2.Surname();
可能吗?如果是,请指导我
问候
Imrankhan
Is it possible? If yes, please guide me
Regard
Imrankhan
推荐答案
据我所知,您需要在webservice的方法中添加"[WebMethod]".
喜欢
As far i know you need to add ''[WebMethod]'' in your method in webservice.
like
[WebMethod]
public string Name(){return "Imrankhan";}
希望有帮助.
Hope this help.
据我所知,您无法从Web服务实例化/返回类. Web服务公开方法而不是类.
As far as I know, you can''t instantiate/return a class from a web service. A web service exposes methods, not classes.
否.您不能直接引用Web服务的名称空间.
您将需要为原始类(托管在服务器上)生成一个代理,然后创建这些代理类的实例.当您向项目中添加服务引用"时,将自动为您生成代理.您仍然需要在代码中实例化这些代理类并调用适当的Web方法.
No. You cannot refer to the namespace of a web service directly.
You will need to generate a proxy for your original classes (hosted on the server) and then create an instance of these proxy classes. The proxy is automatically generated for you when you ''add a service reference'' to your project. You still need to instantiate these proxy classes in your code and call the appropriate web methods.
这篇关于Web服务中的多个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文