有两种方式,静态调用(添加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:

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

    当你查看你的 SSH 服务日志,可能你会发现充斥着一些不怀好意的尝试性登录.这里有 5 条常规建议(和一些个别特殊策略)可以让你的 OpenSSH 会话更加安全. 强化密码登录 密码登录很方便,因为你 ...

  2. Visual Studio 6 (VC6)连接Team Foundation Server (TFS 2018),实现源代码的版本管理

    1. 概述 Visual Studio 6(VB6, VC6, Foxpro-)是微软公司在1998年推出的一款基于Windows平台的软件开发工具,也是微软推出.NET开发框架之前的最后一个IDE工 ...

  3. TFS Training for Kunlun bank (http://www.klb.cn/) 微软研发流程(ALM)管理培训会议(昆仑银行) 2016.09.21

    银行一直是微软技术的伤心地,由于历史原因,微软技术和产品一直很难进入到银行业务的核心区域,但是微软今年来的进步不少,在开发工具和平台方面已经连续攻克了几个典型的金融企业,例如农业银行,中国人保等. 应 ...

  4. 我也谈谈.NET程序员工资低

    我从2011年下半年预谋转型,2012春季正式转型到iOS,看了<经过本人 6 年.net 工作经验证明 .net 工资确实比 Java 低>这篇文章,一下子有很多感慨. 我不好意思算我干 ...

  5. DAC--使用DAC来导出数据库脚本

    //============================================== //功能介绍:使用DAC来导出数据库脚本 //注意事项: //1.本程序涉及到的DLL有: //  - ...

  6. WinForm如何去掉右边和下边的白边

    系统给的窗体样式都缺乏美感,想要漂亮的UI只能自己做,很容易实现 1.新建窗体,设置FormBorder为None 这时的窗体就只有一个Panel(Form自带的默认Panel),没有边框,没有标题栏 ...

  7. js 日期去掉 -

    语法 stringObj.replace(rgExp, replaceText) replace 方法的语法包括下述部分: stringObj 必选项.要执行该替换的 String 对象或文字.该对象 ...

  8. ASP.NET 实现多页面合并一页显示

    目前业务有一个需求: 就是把多个网页合并到一个页面显示, 在实现过程中我一般使用两种方法: 利用母版页设置导航栏, 定位到每个网页; 利用用户控件( .acsx 后缀的文件), 但是有个问题就是传参比 ...

  9. js处理想要得到数据结构

    例1 var arr = [ { date: "2018-01-10", time: "11:00" }, { date: "2018-01-10&q ...

  10. Django安装(第一个项目)

    day60 从系统中选择已存在的解释器. 新建Django项目         命令行创建:             django-admin startproject mysite          ...