0

セッションを存続させるために使用される単純なWebメソッドを作成しました。

Imports System.ServiceModel
Imports System.ServiceModel.Activation
Imports System.ServiceModel.Web

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

' To use HTTP GET, add <WebGet()> attribute. (Default ResponseFormat is WebMessageFormat.Json)
' To create an operation that returns XML,
'     add <WebGet(ResponseFormat:=WebMessageFormat.Xml)>,
'     and include the following line in the operation body:
'         WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml"
<OperationContract()>
Public Shared Function KeepSessionAlive() As Integer

    'Keep the session alive by writing to a session variable
    HttpContext.Current.Session("KeepSessionAlive") = DateTime.Now
    'Give the user time to keep the session alive
    Dim iSecondsToKeepAlive As Integer = 50
    'Set the timeout before the 'keep alive' message is displayed
    Dim iTimeout As Integer = (HttpContext.Current.Session.Timeout * 60000) - (iSecondsToKeepAlive * 1000)
    Return iTimeout

End Function

' Add more operations here and mark them with <OperationContract()>

End Class

私のscriptmanagerは次のように定義されています:

<asp:ScriptManager ID="ScriptManagerMaster" EnablePartialRendering="true" runat="server">
    <Services>
        <asp:ServiceReference Path="~/Shared/WebService.svc" />
    </Services>
</asp:ScriptManager>

すべてのウェブページからこれにアクセスできるようにしたいと思います。私はこれを呼び出すためにwcfサービスを作成しようとしました:

    $('.renew-session').click(function () {
        clearTimeout(modalTimeout);
        var stayAlive = new PMWebService.WebService
        stayAlive.KeepSessionAlive(onTimeoutReturned, onDataFailure);
    });

ただし、これは「var stayAlive = new MyWebService.WebService」で失敗し、PMWebServiceが未定義であることを示します。

http://www.dotnetcurry.com/ShowArticle.aspx?ID=235の例に従ってみました。ただし、これらの手順を実行すると、手順4で違いが生じます。スクリプトマネージャーのプロパティを確認すると、サービスコレクションが表示されません。私のウェブサイトはウェブアプリケーションとして実行されているので、これが違いを生むかどうかはわかりません。

誰かがこれを手伝ってくれることを願っています。これをasmxサービスとして実行しようとしましたが、同じエラーが発生しました。PageMethodとして実行できますが、これを各ページに配置する必要があります。ashxハンドラーも試しましたが、これからタイムアウト値を返すことができないと思います。

4

1 に答える 1

0

私はこれを整理しました。「KeepSessionAlive」の定義から「Shared」を削除する必要がありました。私は別の場所からルーチンをコピーしましたが、定義が間違っていることに気づきませんでした。

于 2012-12-07T21:49:33.223 に答える