zoukankan      html  css  js  c++  java
  • WebService中方法的重载

    阅读目录

      一:WebService中的方法是否允许重载?

      二:为什么WebService中不支持方法的重载?

      三:如何解决WebService中方法的重载?

      一:WebService中的方法是否允许重载?

        WebService中不支持使用方法的重载,从图片我们能够得出结论

    [WebMethod]
     2   public string GetName()
     3   {
     4        return "从小就犯困";
     5   }
     6 
     7   [WebMethod]
     8   public string GetName(string strValue)
     9   {
    10     return strValue;
    11   }

    二:为什么WebService中不支持方法的重载?

        WebService中不支持方法的重载,这还得从WebService的工作机制中说起,当客户端调用一个WebService的方法时,首先要将方法名称和需要传递的参数包装成XML,也就是SOAP包,通过HTTP协议传递到服务器端,然后服务器端解析这段XML,得到被调用的方法名称和传递过来的参数,进而调用WebService相应的方法,方法执行完毕后,将返回结果再次包装为XML,也就是SOAP响应,发送到客户端,最后客户端解析这段XML,最终得到返回结果,关键在于服务器端解析XML时无法识别重载的方法,WebService只认方法的名称,而且两个方法的名称相同,服务器端不知道该调用哪个相应的方法

      三:如何解决WebService中方法的重载?

        可以通过MessageName属性消除由于多个相同的名称造成的Web服务无法识别的问题,因为MessageName属性使得Web服务能够确定唯一别名的重载方法,默认时候是方法本身的名称,当指定MessageName属性后,SOAP将反映MessageName的值,而不是方法名称本身,所以这就解决了WebService中不支持方法的重载

    [WebServiceBinding(ConformsTo = WsiProfiles.None)]
     2   [WebMethod(MessageName="FirstMethod")]
     3   public string GetName()
     4   {
     5        return "从小就犯困";
     6   }
     7 
     8   [WebMethod(MessageName="SecordMethod")]
     9   public string GetName(string strValue)
    10   {
    11     return strValue;
    12   }

    我们现在来看这两个方法的消息名称是不就被区分开了

    转:http://www.cnblogs.com/menglin2010/archive/2012/03/29/2421445.html

  • 相关阅读:
    Conntect Bluetooth devices in iOS.
    Why NSAttributedString import html must be on main thread?
    IOS7 SDK 几宗罪
    How to browse the entire documentation using XCode 5 Documentation and API Reference ?
    High Precision Timers in iOS / OS X
    [UWP]抄抄《CSS 故障艺术》的动画
    [Microsoft Teams]使用连接器接收Azure DevOps的通知
    [WPF 自定义控件]自定义一个“传统”的 Validation.ErrorTemplate
    [WPF 自定义控件]在MenuItem上使用RadioButton
    [WPF 自定义控件]创建包含CheckBox的ListBoxItem
  • 原文地址:https://www.cnblogs.com/wangfuyou/p/6066518.html
Copyright © 2011-2022 走看看