zoukankan      html  css  js  c++  java
  • webservices [WebServiceBinding(ConformsTo = WsiProfiles.None)]

    利用VS建立WebService,.cs文件代码引人注意的首先是属性(Attribute)部分:

        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo 
    = WsiProfiles.BasicProfile1_1)]

    有时为了写带重载方法的WS,需要修改ConformsTo特征(Property)以解除对WS-I标准的绑定:

    [WebServiceBinding(ConformsTo = WsiProfiles.None)]

    注:这是在.cs文件中写重载的WebMethod的必要条件之一 —— 而已。

    附加[WebMethod]特征的方法在默认情况下是不允许重载的(WsiProfiles.BasicProfile1_1 ,要符合“WSI基本概要”1.1的缘故)。带[WebMethod]的方法是面向用户发布为WebService的,公开具有可见性,是XML Web Services的一部分。附加[WebMethod]特征的方法应该是Public的,即服务应该是保持可公开访问的,就好像某某说我的东西是要开源的(附加了[WebMethod])却又静悄悄鬼祟鬼祟地写了版权声明私有(居然是Private)的。所以,给public的方法附加[WebMethod]特征才叫做言行一致。

    .cs类中方法允许(任何时候)重载的示例:

    复制代码
            public string GetValue()
            {
                
    return "string";
            }

            
    public string GetValue(string str)
            {
                
    return "string";
            }
    复制代码

     上面的两个方法没有发布为WebMethod的方法,所以是不须遵循WSI标准的。

    不允许(默认情况下:附加了[WebMethod]属性,遵循WSI)重载的情况: 


            [WebMethod]
            
    public string GetValue()
            {
                
    return "string";
            }

            [WebMethod]
            
    public string GetValue(string str)
            {
                
    return "string";
            }

     public和private的WebMethod比较,可以明白这个世界会因调用有时“笔误”编写的private方法徒劳无功尚且产生错误。


     [WebMethod(Description="我是可见的",MessageName="aMethod")]
            
    public string GetValue()
            {
                
    return "string";
            }

            [WebMethod(Description
    ="你看不到我",MessageName="bMethod")]
            
    private string GetValue(string str)
            {
                
    return "string";
            }

     运行asmx后只看到一个aMethod

    WebMethod方法的重载

    在.Net Framework1.1里只需要两步就能“开通”重载了。

    (1)修改属性WebServiceBinding的ConfromsTo特征(中文MSDN上将两个都称之为属性,尽管英文前者是Attribute后者是Property)

    [WebServiceBinding(ConformsTo = WsiProfiles.None)]

    (2)为WebMethod属性添加MessageName特征,如上面的示例:

     [WebMethod(Description="我是可见的",MessageName="aMethod")]
     [WebMethod(Description="你看不到我",MessageName="bMethod")]

    .Net Framework3.5用的不多,特地试了一下,还要修改配置文件,另话。

    Kyle

  • 相关阅读:
    修改滚动条样式
    svg转png
    封装普通数据为树菜单结构数据模式
    js调用打印机打印
    jq 上传下载进度条
    html内容溢出部分...
    html调用html的方法
    4 人类社会及其发展规律
    7 社会主义
    8 共产主义
  • 原文地址:https://www.cnblogs.com/lovewife/p/2650871.html
Copyright © 2011-2022 走看看