zoukankan      html  css  js  c++  java
  • 跨平台动态引用webservice地址

    在使用PDA(WinCE)引用 webservice,需要把wbservice地址提取出来放入配置文件当中。在这里涉及了两个问题。在网上找的资料

    第一:怎么提取

    第二:PDA 属于跨平台

    现在先处理怎么提取:

    首先我们在PDA引用服务器的WebService比如为:WS_SellManage, 然后在PDA项目里创建一个代理类 DynWebServiceSell.cs,并继承这个webservice的类,在这里为WS_SellManage.SW_SellManage

    [System.Diagnostics.DebuggerStepThrough(),
         System.ComponentModel.DesignerCategory("code"),
         System.Web.Services.WebServiceBinding(Name = "", Namespace = "")]
        public class DynWebServiceSell: WS_SellManage.SW_SellManage//继承webservice
        {
            public DynWebServiceSell(string webUrl)
                : base()
            {
                this.Url = webUrl;
            }
        }

    创建一个app.config用来保存webservice地址。如下

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <appSettings>
         <add key="WS_SellManageKey" value="http://190.160.10.79:80111/WebService/SW_SellManage.asmx"/>
      </appSettings>
    </configuration>

    然后我们在 PDA窗体上的构造函数上使用这个代理类

          DynWebServiceSell ws_Sell = null;

            public Form1()

            {

                InitializeComponent();

                //加载xml文档...

                string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\App.config";

                System.Xml.XmlDocument xmldoc = new System.Xml.XmlDocument();

                xmldoc.Load(path);

                System.Xml.XmlNode node = xmldoc.SelectSingleNode("//configuration/appSettings/add[@key='WS_SellManageKey']");

                if (node != null)

                {

                    ws_Sell = new DynWebServiceSell(node.Attributes["value"].Value);

                }

            }

    使用:

    object[] login = ws_Sell.Login(txtUserName.Text.Trim(), txtPassword.Text.Trim());//Login为webservice方法

    第二个问题跨平台

    如果是单单按上面的方式执行的话会出现:“webserver引用出现”服务器未能识别 HTTP 头 SOAPAction 的值“,按这个错误网上有很多解决的方式。在这里我找到的是需要在webservice类上加上

    [SoapDocumentService(RoutingStyle = SoapServiceRoutingStyle.RequestElement)]

    即:

    /// <summary>

        /// SW_SellManage 的Ì?摘a要°a说¦Ì明¡Â

        /// </summary>

        [WebService(Namespace = "http://tempuri.org/")]

        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

        [System.ComponentModel.ToolboxItem(false)]

        // 若¨?要°a允¨º许¨ª使º1用®? ASP.NET AJAX 从䨮脚?本À?中D调Ì¡Â用®?此ä? Web 服¤t务?,ê?请?取¨?消?对?下?行D的Ì?注Á¡é释º¨ª。¡ê

        // [System.Web.Script.Services.ScriptService]

        [SoapDocumentService(RoutingStyle = SoapServiceRoutingStyle.RequestElement)]

        public class SW_SellManage : System.Web.Services.WebService

        {

            /// <summary>

            /// </summary>

            /// <returns></returns>

            [WebMethod]

            public object[] Login(string userName, string password)

            {}

    }

     这样就不会出现问题了。

  • 相关阅读:
    java 23种设计模式 深入理解
    ORACLE 一条记录 某字段值以';'拆分为多条记录
    rabbitmq集群故障恢复
    ORACLE 时间加减操作
    Asp.net MVC Razor输出字符串方法(js中嵌入razor)
    C# ToString() 数据格式
    DOM的整个知识体系
    EF 连接模式
    EF Code First 数据库连接方式
    使用border实现提示框的
  • 原文地址:https://www.cnblogs.com/KimhillZhang/p/3116620.html
Copyright © 2011-2022 走看看