Почему я получаю сообщение об ошибке при попытке вызвать почтовый веб-сервис с библиотекой flutter chopper? - PullRequest
0 голосов
/ 28 мая 2020

Я пытаюсь передать несколько параметров в веб-службу через библиотеку прерывателя флаттера, которая в остальном работает нормально, но возвращает ошибку с прерывателем флаттера. Вот код.

//This is the chopper client class code

import 'dart:typed_data';
import 'package:chopper/chopper.dart';
import 'package:flutter/cupertino.dart';
part "staff_webservice.chopper.dart";

@ChopperApi(baseUrl: "/StaffWebservice.asmx")
abstract class StaffWebService extends ChopperService {

  @Post(path:"/StaffLogin",headers: {
  "Content-Type": "application/x-www-form-urlencoded"
  })
  Future<Response> login(
  @Field("UserName") String UserName,
      @Field("Password") String Password,
      @Field("DOB") String DOB,
      );


  static StaffWebService create() {
    final client = ChopperClient(
      baseUrl: "http://epunjabschool.gov.in/Webservice",
      services: [
        _$StaffWebService()
      ],
      converter: JsonConverter(),

    );
    return _$StaffWebService(client);
  }
}

Вот сгенерированный код класса.

// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'staff_webservice.dart';

// **************************************************************************
// ChopperGenerator
// **************************************************************************

class _$StaffWebService extends StaffWebService {
  _$StaffWebService([ChopperClient client]) {
    if (client == null) return;
    this.client = client;
  }

  final definitionType = StaffWebService;

  Future<Response> login(String UserName, String Password, String DOB) {
    final $url = '/StaffWebservice.asmx/StaffLogin';
    final $headers = {'Content-Type': 'application/x-www-form-urlencoded'};
    final $body = {'UserName': UserName, 'Password': Password, 'DOB': DOB};
    final $request =
        Request('POST', $url, client.baseUrl, body: $body, headers: $headers);
    return client.send<dynamic, dynamic>($request);
  }
}

И вот как я пытаюсь вызвать этот метод, но всегда получаю сообщение об ошибке.

try {
      final response = await staffWebService.login(
          "8146166001","gurjot85","15-sep-1985");

      print(response.body.toString());


      setState(() {
      });
    }
    catch(error)
    {

    }

Это ошибка:

<code><!DOCTYPE html>
<html>
    <head>
        <title>Only Web services with a [ScriptService] attribute on the class definition can be called from script.</title>
        <meta name="viewport" content="width=device-width" />
        <style>
         body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} 
         p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
         b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
         H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
         H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
         pre {font-family:"Consolas","Lucida Console",Monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt}
         .marker {font-weight: bold; color: black;text-decoration: none;}
         .version {color: gray;}
         .error {margin-bottom: 10px;}
         .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
         @media screen and (max-width: 639px) {
          pre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; }
         }
         @media screen and (max-width: 479px) {
          pre { width: 280px; }
         }
        </style>
    </head>

    <body bgcolor="white">

            <span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>

            <h2> <i>Only Web services with a [ScriptService] attribute on the class definition can be called from script.</i> </h2></span>

            <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">

            <b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

            <br><br>

            <b> Exception Details: </b>System.InvalidOperationException: Only Web services with a [ScriptService] attribute on the class definition can be called from script.<br><br>

            <b>Source Error:</b> <br><br>

            <table width=100% bgcolor="#ffffcc">
               <tr>
                  <td>
                      <code>

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</code>

                  </td>
               </tr>
            </table>

            <br>

            <b>Stack Trace:</b> <br><br>

            <table width=100% bgcolor="#ffffcc">
               <tr>
                  <td>
                      <code><pre>

[InvalidOperationException: Only Web services with a [ScriptService] attribute on the class definition can be called from script.]
   System.Web.Script.Services.WebServiceData..ctor(Type type, Boolean pageMethods) +719604
   System.Web.Script.Services.WebServiceData.GetWebServiceData(HttpContext context, String virtualPath, Boolean failIfNoData, Boolean pageMethods, Boolean inlineScript) +301
   System.Web.Script.Services.RestHandler.CreateHandler(HttpContext context) +136
   System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated) +89
   System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +516
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +288

Информация о версии: Microsoft. NET Версия Framework: 4.0.30319; ASP. NET Версия: 4.0.30319.34009
...