zoukankan      html  css  js  c++  java
  • cathome 猫家 开发日记-webservice服务 ,生成json. 以及500错误

    概述,采用熟悉的c# 语言。

    1.用asmx 。微软的web服务的标准格式。方便。如参数的post,在服务端,跟写普通函数一样,写参数就行,不用考虑http request.

    2.由方法生成json字符。只是利用ms 的框架而已。

    配置文档。

    <?xml version="1.0" encoding="utf-8"?>
    <!--
      有关如何配置 ASP.NET 应用程序的详细信息,请访问
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5" />
        <webServices>
          <protocols>
            <add name="HttpPost"/>
            <add name="HttpGet"/>
          </protocols>
        </webServices>
      </system.web>
      <connectionStrings>
        <add name="dbstr" connectionString="Data Source=localhost;Initial Catalog=mycity;User ID=sa;Password="/>
      </connectionStrings>
    </configuration>

    方法

     /// <summary>
        /// WebService1 的摘要说明
        /// </summary>
        [WebService(Namespace="mycity")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        [System.Web.Script.Services.ScriptService]
    
        public class MainPage : System.Web.Services.WebService
        {
           //商家的大类
            [WebMethod(Description = "商家的大类")]
            public void Category_MainCategory()
            {
                List<Model.VCategory_All> category = bll_category.GetModelList("cg_fatherid='0'");
                string jasonCategory = Function.ConvertJson.ListToJson(category);
                Context.Response.Write(jasonCategory);
                Context.Response.End();
            }

    调用方:注意是请求的页面是/直接加方法名字

    http://xxxxx/add.asmx/add

    错误:

    如果发生500错误。

    1.加httppost协议

    <protocols>
            <add name="HttpPost"/>
            <add name="HttpGet"/>
          </protocols>
    2.注意http uri的写法。注意是请求的页面是/直接加方法名字。 微软提供的?op=add 这个页面不是请求页。可以把它作为一个友好帮助页。
    3.可以先用一个无参的方法测试。排除参数问题。
  • 相关阅读:
    J2EE规范标准
    怎样用Google APIs和Google的应用系统进行集成(4)----获得Access Token以通过一些Google APIs的OAuth2认证
    [BestCoder Round #3] hdu 4908 BestCoder Sequence (计数)
    大数据存储之分布式文件系统(一)
    List与array的相互转换
    TRIZ系列-创新原理-31-多孔材料原理
    关于app.FragmentManager和v4包的FragmentPagerAdapter冲突
    POJ 1163 The Triangle
    ChinaVis2015 第一天会议
    JSON初入门
  • 原文地址:https://www.cnblogs.com/lsfv/p/9921807.html
Copyright © 2011-2022 走看看