有两种方式,静态调用(添加web服务的暂且这样定义)和动态调用:

静态调用:
使用添加web服务的方式支持各种参数,由于vs2010会自动转换,会生成一个特定的Reference.cs类文件

 

动态调用:
通过soap/get/post方法动态调用webservices,只支持string类型或数组类型

否则执行

XmlSerializer mySerializer = new XmlSerializer(o.GetType());

会报错:
不支持类型 System.Collections.Hashtable,因为它实现 IDictionary。

说明:静态调用也是将其它数据类型转换成Object[]类型的数组来传参
譬如java中HashMap类型,vs2010转换后的情况如下:

Reference.cs:

//------------------------------------------------------------------------------
// <auto-generated>
//     此代码由工具生成。
//     运行时版本:4.0.30319.1008
//
//     对此文件的更改可能会导致不正确的行为,并且如果
//     重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
 
// 
// 此源代码是由 Microsoft.VSDesigner 4.0.30319.1008 版自动生成。
// 
#pragma warning disable 1591
 
namespace WinFormFunction.localhost {
    using System;
    using System.Web.Services;
    using System.Diagnostics;
    using System.Web.Services.Protocols;
    using System.ComponentModel;
    using System.Xml.Serialization;
    
    
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "4.0.30319.1")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Web.Services.WebServiceBindingAttribute(Name="CreateGevtIncidentServiceHttpBinding", Namespace="http://alarm.mobile.work.inter.bomc.boco.com")]
    public partial class CreateGevtIncidentService : System.Web.Services.Protocols.SoapHttpClientProtocol {
        
        private System.Threading.SendOrPostCallback createIncidentOperationCompleted;
        
        private bool useDefaultCredentialsSetExplicitly;
        
        /// <remarks/>
        public CreateGevtIncidentService() {
            this.Url = global::WinFormFunction.Properties.Settings.Default.WinFormFunction_localhost_CreateGevtIncidentService;
            if ((this.IsLocalFileSystemWebService(this.Url) == true)) {
                this.UseDefaultCredentials = true;
                this.useDefaultCredentialsSetExplicitly = false;
            }
            else {
                this.useDefaultCredentialsSetExplicitly = true;
            }
        }
        
        public new string Url {
            get {
                return base.Url;
            }
            set {
                if ((((this.IsLocalFileSystemWebService(base.Url) == true) 
                            && (this.useDefaultCredentialsSetExplicitly == false)) 
                            && (this.IsLocalFileSystemWebService(value) == false))) {
                    base.UseDefaultCredentials = false;
                }
                base.Url = value;
            }
        }
        
        public new bool UseDefaultCredentials {
            get {
                return base.UseDefaultCredentials;
            }
            set {
                base.UseDefaultCredentials = value;
                this.useDefaultCredentialsSetExplicitly = true;
            }
        }
        
        /// <remarks/>
        public event createIncidentCompletedEventHandler createIncidentCompleted;
        
        /// <remarks/>
        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("", RequestNamespace="http://alarm.mobile.work.inter.bomc.boco.com", ResponseNamespace="http://alarm.mobile.work.inter.bomc.boco.com", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
        [return: System.Xml.Serialization.XmlArrayAttribute("out", IsNullable=true)]
        [return: System.Xml.Serialization.XmlArrayItemAttribute("entry", IsNullable=false)]
        public anyType2anyTypeMapEntry[] createIncident([System.Xml.Serialization.XmlArrayAttribute(IsNullable=true)] [System.Xml.Serialization.XmlArrayItemAttribute("entry", IsNullable=false)] anyType2anyTypeMapEntry[] map) {
            object[] results = this.Invoke("createIncident", new object[] {
                        map});
            return ((anyType2anyTypeMapEntry[])(results[0]));
        }
        
        /// <remarks/>
        public void createIncidentAsync(anyType2anyTypeMapEntry[] map) {
            this.createIncidentAsync(map, null);
        }
        
        /// <remarks/>
        public void createIncidentAsync(anyType2anyTypeMapEntry[] map, object userState) {
            if ((this.createIncidentOperationCompleted == null)) {
                this.createIncidentOperationCompleted = new System.Threading.SendOrPostCallback(this.OncreateIncidentOperationCompleted);
            }
            this.InvokeAsync("createIncident", new object[] {
                        map}, this.createIncidentOperationCompleted, userState);
        }
        
        private void OncreateIncidentOperationCompleted(object arg) {
            if ((this.createIncidentCompleted != null)) {
                System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
                this.createIncidentCompleted(this, new createIncidentCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
            }
        }
        
        /// <remarks/>
        public new void CancelAsync(object userState) {
            base.CancelAsync(userState);
        }
        
        private bool IsLocalFileSystemWebService(string url) {
            if (((url == null) 
                        || (url == string.Empty))) {
                return false;
            }
            System.Uri wsUri = new System.Uri(url);
            if (((wsUri.Port >= 1024) 
                        && (string.Compare(wsUri.Host, "localHost", System.StringComparison.OrdinalIgnoreCase) == 0))) {
                return true;
            }
            return false;
        }
    }
    
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.1009")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://alarm.mobile.work.inter.bomc.boco.com")]
    public partial class anyType2anyTypeMapEntry {
        
        private object keyField;
        
        private object valueField;
        
        /// <remarks/>
        public object key {
            get {
                return this.keyField;
            }
            set {
                this.keyField = value;
            }
        }
        
        /// <remarks/>
        public object value {
            get {
                return this.valueField;
            }
            set {
                this.valueField = value;
            }
        }
    }
    
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "4.0.30319.1")]
    public delegate void createIncidentCompletedEventHandler(object sender, createIncidentCompletedEventArgs e);
    
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "4.0.30319.1")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    public partial class createIncidentCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
        
        private object[] results;
        
        internal createIncidentCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : 
                base(exception, cancelled, userState) {
            this.results = results;
        }
        
        /// <remarks/>
        public anyType2anyTypeMapEntry[] Result {
            get {
                this.RaiseExceptionIfNecessary();
                return ((anyType2anyTypeMapEntry[])(this.results[0]));
            }
        }
    }
}
 
#pragma warning restore 1591

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

调用:

localhost.CreateGevtIncidentService client = new localhost.CreateGevtIncidentService();

localhost.anyType2anyTypeMapEntry atatm1 = new localhost.anyType2anyTypeMapEntry();

localhost.anyType2anyTypeMapEntry atatm2 = new localhost.anyType2anyTypeMapEntry();

atatm1.key = "title";

atatm1.value = "test title";

atatm2.key = "content";

atatm2.value = "testContent";

localhost.anyType2anyTypeMapEntry[] test=client.createIncident(new localhost.anyType2anyTypeMapEntry[] { atatm1,atatm2});

logger.Info(test.ToString());

c#调用webservices的更多相关文章

  1. ajax调用WebServices服务方法和传参调用WebServices注意事项

    先演示下ajax是如何调用WebServices中的方法    1.新建一个页面default.aspx,一个Web服务    在页面中引用jQuery文件. <script src=" ...

  2. php利用SoapClient调用webservices

    原文:php利用SoapClient调用webservices 1.开启soap支持,在php.ini中去除extension=php_soap.dll之前的':' 2.掉用页面 <?php h ...

  3. C#利用WinForm调用WebServices实现增删改查

    实习导师要求做一个项目,用Winform调用WebServices实现增删改查的功能.写下这篇博客,当做是这个项目的总结.如果您有什么建议,可以给我留言.欢迎指正. 1.首先,我接到这个项目的时候,根 ...

  4. 关于C#调用WebServices的方法

    2018-1-22 前情是我使用vs在引用高通的webservice时出现了下载错误导致无法引用这个服务,先是在网上查询了这个错误的问题及解决方案,将这个问题与解决方法发给了高通同事,可惜的是他也不清 ...

  5. jquery Ajax跨域调用WebServices方法

    由于公司需要开发一个手机页面,想提供给同事直接在手机上可以查询SAP资料.数据需要使用js调用webserver来获取. 因为初次使用Jquery调用Webserver,所以期间并不顺利.测试调用We ...

  6. java调用 webservices接口实现天气预报

    最近要用到web services,而这两天也比较有空,就弄了一个获取天气预报的Util.以前以为这有多难,因为数据来源是个困难.现在用web services的技术,发现下面这个是相当不错的.下面就 ...

  7. android应用一(调用WebServices)

    搞了一个月的android,现学现卖,终于还是搞完了,停下来,整理思路,写写记录吧. 我们知道android访问远程数据库主要有两种协议,一种是SOAP,另外一种就是HTTP.而我们再看看WebSer ...

  8. c# 调用 webservices (转载)

    .net 调用webservice 总结 最近做一个项目,由于是在别人框架里开发app,导致了很多限制,其中一个就是不能直接引用webservice . 我们都知道,调用webserivice 最简单 ...

  9. 一个简单的winform程序调用webservices

    本文原创,如需转载,请标明源地址,谢谢合作!http://blog.csdn.net/sue_1989/article/details/6597078 本文的编写IDE为VSTS2008和.NET F ...

随机推荐

  1. Asp.Net 跨域,Asp.Net MVC 跨域,Session共享,CORS,Asp.Net CORS,Asp.Net MVC CORS,MVC CORS

    比如 http://www.test.com 和 http://m.test.com 一.简单粗暴的方法 Web.Config <system.web> <!--其他配置 省略……- ...

  2. 使用MEF与Castle实现AOP

    MEF是微软的一个ioc框架,使用非常方便,我们只需要在需要导出的类上标记[Export],在需要使用的地方[import]就可以使用了.现在我们扩展MEF,在其装配生成实例时,使用Castle Dy ...

  3. sql server生成自动增长的字母数字字符串

    在开发的过程中,我们经常会遇到要生成一些固定格式字符串,例如“BX201903150001”,结构为:BX+日期+N位序号,类似这种的字符串我们很难生成,在这里我们借助一个存储过程来实现这个功能. 1 ...

  4. JVM伪共享

    CPU缓存中的cache line缓存行是缓存的最小单位,同一个时刻内只允许一个cpu内核进行操作.一般,缓存行的大小为64字节,这样的大小可以存放多个java对象的对象头.因此,当两个不同的线程同时 ...

  5. 为什么选择AJPFX

    外汇贵金属交易市场是全球最大的金融产品市场,日均交易量达到5万亿美元,相当于美国证券市场的40倍,中国股票市场日均交易量的700倍,它的主要优势在于其透明度较高,由于交易量巨大,主力资金(如政府外汇储 ...

  6. Notification通知栏的使用

    一.基础的知识了解 1.pendingIntent : 它是Intent的封装,可以跳转某个Activity.给Service发送一个命令.还可以发送一个广播 2.进度条的使用方法 3.更新通知栏的信 ...

  7. 【ocp新题】OCP 12c 062认证考试出现大量新题-8

    8. Which are two ways for a database service to be recognized by a listener in Oracle Database 12c? ...

  8. Flask 实现 WebSocket 通讯---群聊和私聊

    一.WebSocket介绍 WebSocket是一种在单个TCP连接实现了服务端和客户端进行双向文本或二进制数据通信的一种通信的协议. WebSocket使得客户端和服务器之间的数据交换变得更加简单, ...

  9. Flask从入门到精通之Jinja2模板引擎

    我们使用一个简单的例子切入到Jinja2模板引擎,形式最简单的Jinja2模板引擎就是一个包含响应文本的文件,实例如下: <h1>Hello World!</h1> 最简单的包 ...

  10. 了解ORACLE培训OCA-OCP-OCM课程表

    了解ORACLE培训OCA-OCP-OCM课程表考试号: OCA    1Z0-007$125    Oracle Database 10g:SQL Fundamentals 本课程培养学生必要的SQ ...