在Web服务中构建 [英] Construction Using in Web Services

查看:58
本文介绍了在Web服务中构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Coders,
我想在我的网络服务中使用参数化构造。我做了但是当我发表它。建筑物似乎没有。

例如:

public class VirtualClassServices :System.Web.Services。 WebService

Hi Coders,
I want to use parametered construction in my web service. I did but when i published it. The Constructs don't seem.

For  example:

public class VirtualClassServices : System.Web.Services.WebService

{

{

    

public int UserID { get ; set ; }

public int UserID { get; set; }

public < font color ="#2b91af"size = 2> Guid UserTicket { get ; set ; }

public Guid UserTicket { get; set; }

public < font color ="#2b91af"size = 2> 登录 LoginState UserState { get ; set ;}

public Login.LoginState UserState { get; set;}

public string ErrorException { get ; set ; }

public string ErrorException { get; set; }

 

public VirtualClassServices( int userID, Guid userTicket)

public VirtualClassServices(int userID, Guid userTicket )

{

UserID = userID;

UserID = userID;

UserTicket = userTicket;

UserTicket = userTicket;

}

public VirtualClassServices()

public VirtualClassServices()

{

}





当我想使用网络时在项目中的服务我看不到构造。我想要做的是:每个方法都必须使用UserID和Ticket。我不想在每种方法中都获得参数。声明Web服务使用时我希望得到它。所以我需要建设。例如。

我将web服务添加到我的引用后:


}


When i want to use the web service in a project i can't see the construct. The thing i want to do it is that: For every method has to use UserID and Ticket. I don't want to get as parameters in every methods. When declares the web service to using i want to get it that time. so i need the construction. For example.

After i added the web service to my referenceses:

VirtualClassWebService。 VirtualClassServices vcs = new BussinesObjects.VirtualClassWebService。 < font color ="#2b91af"size = 2> VirtualClassServices ();

VirtualClassWebService.VirtualClassServices vcs = new BussinesObjects.VirtualClassWebService.VirtualClassServices();

我看不到建筑。我的代码中有错误吗?

我希望我能解释一下我的问题。谢谢:)



i can't see the construction. Is there any errror in my codes? 

I hope i could explained my problem. Thanks :)




推荐答案

您好,每次当您调用Web服务时,ASMX处理程序创建VirtualClassServices的新实例,并使用默认的无参数构造函数。您将无法调用参数化构造函数。

因此,您的方法将无法正常工作。

您可以在此处选择:
1。您可以在Web服务中使用Session。但请注意,这会损害Web服务的可伸缩性。在这种情况下,您可以调用一个初始化方法,在会话中存储所有用户信息,然后调用任何其他方法,这些方法将转向Session并读取必要的值。
2。增强您的客户端代理类。在内部通过代理类中的每个Web方法传递用户令牌。例如:
public class VirtualClassServicesProxy:SoapHTTPClientProtocol
{
public VirtualClassServicesProxy(int userID,Guid userToken):base()
{
this._userID = userID;
this._userToken = userToken;



public int SomeMethod(int parameter1,int parameter2)
{
return this.GeneratedByVisualStudioWebMethodCall(_userID,_userToken,parameter1,parameter2);
}
}结果,3。考虑SOAP扩展。
Hi,

Each time when you call Web Service, ASMX handler creates NEW instance of VirtualClassServices and uses default parameterless constructor. You won't have an ability to call your parametrized constructor.

Therefore your approach won't work.

Here you have few options:
1. You can use Session in your Web Service. But be aware, that this can hurt scalability of your Web Service. In this case you can call one initialization method, store all user info in session, and then call any other methods, that will turn to Session and read necessary values.
2. Enhance your client proxy class. Pass user token in each web method in your proxy class internally. For instance:
public class VirtualClassServicesProxy: SoapHTTPClientProtocol
{
    public VirtualClassServicesProxy(int userID, Guid userToken) : base()
    {
        this._userID = userID;
        this._userToken = userToken;
    }

    public int SomeMethod(int parameter1, int parameter2)
    {
        return this.GeneratedByVisualStudioWebMethodCall(_userID, _userToken, parameter1, parameter2);
    }
}
3. Consider SOAP extension.


这篇关于在Web服务中构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆