我想在Web服务方法中初始化一些将在每个Web方法中使用的值 [英] I want to initialize some values in web service method that will be used in every web method

查看:102
本文介绍了我想在Web服务方法中初始化一些将在每个Web方法中使用的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Web服务方法中初始化一些将在每个Web方法中使用的值(变量),而不使用session var(httpContext)

我想变量会在每种方法中丢失其值



 <   ServiceContract(Namespace:  " ">> 
<   AspNetCompatibilityRequirements(RequirementsMode:  =   AspNetCompatibilityRequirementsMode.Allowed) > 
公共类服务

    昏暗为整数
    dim b作为整数
    <   OperationContract  > 
    公共函数init2(ByVal a1作为整数,ByVal b1作为整数)作为整数
        a = a1
        b = b1
        
        返回a1 + b1
    结束功能

    <   OperationContract() > 
    公共函数DoValue()作为整数
        返回a + b结束函数

结束类

解决方案

是的,我想是这样.网络是无状态的.当几个人一次使用您的Web服务时会发生什么?


状态应该是一个实例(一个会话)的维护者,其他用户将获得自己的状态(会话),就像一个实例一样类的值应该在方法之间保持值

I want to initialize some values(variables) in web service method that will be used in every web method,without using session var (httpContext)

i guess variables will lose its values , in every method



<ServiceContract(Namespace:="")>
<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)>
Public Class Service

    Dim a As Integer
    dim b As Integer
    <OperationContract>
    Public Function init2(ByVal a1 As Integer, ByVal b1 As Integer) As Integer
        a = a1
        b = b1
        
        Return a1 + b1
    End Function

    <OperationContract()>
    Public Function DoValue() As Integer
        Return  a+ b    End Function

End Class

解决方案

Yes, I would imagine so. The web is stateless. What happens when several people are using your webservice at once ?


state should be maintin for one instance (one session), other users will get theier own states (sessions) , its like one instance of the class should maintain the value among the methods


这篇关于我想在Web服务方法中初始化一些将在每个Web方法中使用的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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