2018-1-22


 前情是我使用vs在引用高通的webservice时出现了下载错误导致无法引用这个服务,先是在网上查询了这个错误的问题及解决方案,将这个问题与解决方法发给了高通同事,可惜的是他也不清楚怎么回事,没有办法我只好再去查阅资料看看其他方法;这里总结几种方法


第一种:最常见的就是直接在项目的引用中右击添加服务引用

此方法用法如下:

首先需要添加引用;然后需要实例化,实例化完了之后就可以通过实例化的对象调用webservices的方法;

这个方法以前常用,可惜这次不行了;

第二种:不用通过引用,直接调用webservices

此方法又分为了几种:

https://www.cnblogs.com/weicanpeng/p/5755987.html  这是原网址。

(1)使用HttpWebRequest 向WebService发送POST请求,并将请求头:ContentType = "application/json;charset=utf-8",参数以JSON方式发送给WebService

        /// <summary>
/// 需要WebService支持Post调用
/// </summary>
public static string PostWebServiceByJson(String URL, String MethodName, Hashtable Pars)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL + "/" + MethodName);
request.Method = "POST";
request.ContentType = "application/json;charset=utf-8";
request.Credentials = CredentialCache.DefaultCredentials;
request.Timeout = 10000;
byte[] data = Encoding.UTF8.GetBytes(HashtableToJson(Pars));
request.ContentLength = data.Length;
Stream writer = request.GetRequestStream();
writer.Write(data, 0, data.Length);
writer.Close(); StreamReader sr = new StreamReader(request.GetResponse().GetResponseStream(), Encoding.UTF8);
String retXml = sr.ReadToEnd();
sr.Close();
return retXml;
}

调用方法如下:

            Hashtable ht = new Hashtable();
ht.Add("LoginName", "Admin");
ht.Add("Password", "Password");
ht.Add("AppKey", "123"); HttpHelper.PostWebServiceByJson("http://localhost/OpenApi/MobileService.asmx", "Login", ht);

注意以上调用WebService方法,需要在WebService中将以下代码中的[System.Web.Script.Services.ScriptService]注释去掉

 // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
[System.Web.Script.Services.ScriptService]

 (2)根据WebService文档对应方法说明(例如参数提交方式,请求)发送POST或Get请求

SOAP 1.1

以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。

POST /OpenApi/MobileService.asmx HTTP/1.1
Host: gps.szwearable.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/Login" <?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Login xmlns="http://tempuri.org/">
<LoginName>string</LoginName>
<Password>string</Password>
<AppKey>string</AppKey>
</Login>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length <?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<LoginResponse xmlns="http://tempuri.org/">
<LoginResult>boolean</LoginResult>
</LoginResponse>
</soap:Body>
</soap:Envelope>
 以上Soap1.1示例相应代码如下
 public static string SoapV1_1WebService(String URL, String MethodName, Hashtable Pars, string XmlNs)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL);
request.Method = "POST";
request.ContentType = "text/xml; charset=utf-8";
request.Headers.Add("SOAPAction", "\"" + XmlNs + (XmlNs.EndsWith("/") ? "" : "/") + MethodName + "\"");
// 凭证
request.Credentials = CredentialCache.DefaultCredentials;
//超时时间
request.Timeout = 10000;
byte[] data = HashtableToSoap(Pars, XmlNs, MethodName);
request.ContentLength = data.Length;
Stream writer = request.GetRequestStream();
writer.Write(data, 0, data.Length);
writer.Close();
var response = request.GetResponse();
XmlDocument doc = new XmlDocument();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
String retXml = sr.ReadToEnd();
sr.Close();
doc.LoadXml(retXml);
XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable);
mgr.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
String xmlStr = doc.SelectSingleNode("//soap:Body/*/*", mgr).InnerXml; return xmlStr;
}
private static string ObjectToSoapXml(object o)
{
XmlSerializer mySerializer = new XmlSerializer(o.GetType());
MemoryStream ms = new MemoryStream();
mySerializer.Serialize(ms, o);
XmlDocument doc = new XmlDocument();
doc.LoadXml(Encoding.UTF8.GetString(ms.ToArray()));
if (doc.DocumentElement != null)
{
return doc.DocumentElement.InnerXml;
}
else
{
return o.ToString();
}
}
private static byte[] HashtableToSoap(Hashtable ht, String XmlNs, String MethodName)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"></soap:Envelope>");
XmlDeclaration decl = doc.CreateXmlDeclaration("1.0", "utf-8", null);
doc.InsertBefore(decl, doc.DocumentElement);
XmlElement soapBody = doc.CreateElement("soap", "Body", "http://schemas.xmlsoap.org/soap/envelope/"); XmlElement soapMethod = doc.CreateElement(MethodName);
soapMethod.SetAttribute("xmlns", XmlNs);
foreach (string k in ht.Keys)
{ XmlElement soapPar = doc.CreateElement(k);
soapPar.InnerXml = ObjectToSoapXml(ht[k]);
soapMethod.AppendChild(soapPar);
}
soapBody.AppendChild(soapMethod);
doc.DocumentElement.AppendChild(soapBody);
return Encoding.UTF8.GetBytes(doc.OuterXml);
}

调用方法如下

  Hashtable ht = new Hashtable();
ht.Add("LoginName", "Admin");
ht.Add("Password", "Password");
ht.Add("AppKey", "123"); var data = HttpHelper.SoapV1_1WebService("http://localhost/OpenApi/MobileService.asmx", "Login", ht, "http://tempuri.org/");

我是用SOAP1.1这个方法成功调用的;

此方法可以多加使用,当然有更好的方法时可以考虑使用更好的方法。

SOAP 1.2

以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。

POST /OpenApi/MobileService.asmx HTTP/1.1
Host: gps.szwearable.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length <?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<Login xmlns="http://tempuri.org/">
<LoginName>string</LoginName>
<Password>string</Password>
<AppKey>string</AppKey>
</Login>
</soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length <?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<LoginResponse xmlns="http://tempuri.org/">
<LoginResult>boolean</LoginResult>
</LoginResponse>
</soap12:Body>
</soap12:Envelope>
以上Soap1.2示例相应代码如下

        public static string SoapV1_2WebService(String URL, String MethodName, Hashtable Pars, string XmlNs)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL);
request.Method = "POST";
request.ContentType = "application/soap+xml; charset=utf-8"; // 凭证
request.Credentials = CredentialCache.DefaultCredentials;
//超时时间
request.Timeout = 10000;
byte[] data = HashtableToSoap12(Pars, XmlNs, MethodName);
request.ContentLength = data.Length;
Stream writer = request.GetRequestStream();
writer.Write(data, 0, data.Length);
writer.Close();
var response = request.GetResponse();
XmlDocument doc = new XmlDocument();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
String retXml = sr.ReadToEnd();
sr.Close();
doc.LoadXml(retXml);
XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable);
mgr.AddNamespace("soap12", "http://www.w3.org/2003/05/soap-envelope");
String xmlStr = doc.SelectSingleNode("//soap12:Body/*/*", mgr).InnerXml; return xmlStr;
} private static byte[] HashtableToSoap12(Hashtable ht, String XmlNs, String MethodName)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\"></soap12:Envelope>");
XmlDeclaration decl = doc.CreateXmlDeclaration("1.0", "utf-8", null);
doc.InsertBefore(decl, doc.DocumentElement);
XmlElement soapBody = doc.CreateElement("soap12", "Body", "http://www.w3.org/2003/05/soap-envelope"); XmlElement soapMethod = doc.CreateElement(MethodName);
soapMethod.SetAttribute("xmlns", XmlNs);
foreach (string k in ht.Keys)
{ XmlElement soapPar = doc.CreateElement(k);
soapPar.InnerXml = ObjectToSoapXml(ht[k]);
soapMethod.AppendChild(soapPar);
}
soapBody.AppendChild(soapMethod);
doc.DocumentElement.AppendChild(soapBody);
return Encoding.UTF8.GetBytes(doc.OuterXml);
}
private static string ObjectToSoapXml(object o)
{
XmlSerializer mySerializer = new XmlSerializer(o.GetType());
MemoryStream ms = new MemoryStream();
mySerializer.Serialize(ms, o);
XmlDocument doc = new XmlDocument();
doc.LoadXml(Encoding.UTF8.GetString(ms.ToArray()));
if (doc.DocumentElement != null)
{
return doc.DocumentElement.InnerXml;
}
else
{
return o.ToString();
}
}

调用方法如下

       Hashtable ht = new Hashtable();
ht.Add("LoginName", "Admin");
ht.Add("Password", "Password");
ht.Add("AppKey", "123");
var data = HttpHelper.SoapV1_2WebService("http://localhost/OpenApi/MobileService.asmx", "Login", ht, "http://tempuri.org/");

HTTP GET

以下是 HTTP GET 请求和响应示例。所显示的占位符需替换为实际值。

GET /OpenApi/MobileService.asmx/Login?LoginName=string&Password=string&AppKey=string HTTP/1.1
Host: gps.szwearable.com
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length <?xml version="1.0" encoding="utf-8"?>
<boolean xmlns="http://tempuri.org/">boolean</boolean>  以上GET示例相应代码如下
 /// <summary>
/// 需要WebService支持Get调用
/// </summary>
public static string WebServiceGet(String URL, String MethodName, Hashtable Pars)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL + "/" + MethodName + "?" + HashtableToPostData(Pars));
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
// 凭证
request.Credentials = CredentialCache.DefaultCredentials;
//超时时间
request.Timeout = 10000;
var response = request.GetResponse();
var stream = response.GetResponseStream();
StreamReader sr = new StreamReader(stream, Encoding.UTF8);
String retXml = sr.ReadToEnd();
sr.Close();
return retXml;
}
private static String HashtableToPostData(Hashtable ht)
{
StringBuilder sb = new StringBuilder();
foreach (string k in ht.Keys)
{
if (sb.Length > 0)
{
sb.Append("&");
}
sb.Append(HttpUtility.UrlEncode(k) + "=" + HttpUtility.UrlEncode(ht[k].ToString()));
}
return sb.ToString();
}

调用方法如下

Hashtable ht = new Hashtable();
ht.Add("LoginName", "Admin");
ht.Add("Password", "Password");
ht.Add("AppKey", "123"); var data = HttpHelper.WebServiceGet("http://localhost/OpenApi/MobileService.asmx", "Login", ht);

HTTP POST

以下是 HTTP POST 请求和响应示例。所显示的占位符需替换为实际值。

POST /OpenApi/MobileService.asmx/Login HTTP/1.1
Host: gps.szwearable.com
Content-Type: application/x-www-form-urlencoded
Content-Length: length LoginName=string&Password=string&AppKey=string
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length <?xml version="1.0" encoding="utf-8"?>
<boolean xmlns="http://tempuri.org/">boolean</boolean>

以上POST示例相应代码如下

         /// <summary>
/// 需要WebService支持Post调用
/// </summary>
public static string PostWebService(String URL, String MethodName, Hashtable ht)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL + "/" + MethodName);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
// 凭证
request.Credentials = CredentialCache.DefaultCredentials;
//超时时间
request.Timeout = 10000;
var PostStr = HashtableToPostData(ht);
byte[] data = System.Text.Encoding.UTF8.GetBytes(PostStr);
request.ContentLength = data.Length;
Stream writer = request.GetRequestStream();
writer.Write(data, 0, data.Length);
writer.Close();
var response = request.GetResponse();
var stream = response.GetResponseStream();
StreamReader sr = new StreamReader(stream, Encoding.UTF8);
String retXml = sr.ReadToEnd();
sr.Close();
return retXml;
} private static String HashtableToPostData(Hashtable ht)
{
StringBuilder sb = new StringBuilder();
foreach (string k in ht.Keys)
{
if (sb.Length > 0)
{
sb.Append("&");
}
sb.Append(HttpUtility.UrlEncode(k) + "=" + HttpUtility.UrlEncode(ht[k].ToString()));
}
return sb.ToString();
}

调用方法如下

  Hashtable ht = new Hashtable();
ht.Add("LoginName", "Admin");
ht.Add("Password", "Password");
ht.Add("AppKey", "123");
var data = HttpHelper.PostWebService("http://localhost/OpenApi/MobileService.asmx", "Login", ht);

WebService支持Post和Get方法

在Web.config,那么只需要修改或添加这么一段

<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>


还有一个说是动态添加,可惜我还是没有用成功

附上此动态调用代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.IO;
using System.Web.Services.Description;
using System.CodeDom;
using Microsoft.CSharp;
using System.CodeDom.Compiler;
using System.Reflection;
using System.Xml.Serialization;
using System.Text; namespace DeliveryGT
{
public class AddWebServices
{
/// < summary>
/// 动态调用web服务
/// < /summary>
/// < param name="url">WSDL服务地址< /param>
/// < param name="methodname">方法名< /param>
/// < param name="args">参数< /param>
/// < returns>< /returns>
public static object InvokeWebService(string url, string methodname, object[] args)
{
return AddWebServices.InvokeWebService(url, null, methodname, args);
}
/// < summary>
/// 动态调用web服务
/// < /summary>
/// < param name="url">WSDL服务地址< /param>
/// < param name="classname">类名< /param>
/// < param name="methodname">方法名< /param>
/// < param name="args">参数< /param>
/// < returns>< /returns>
public static object InvokeWebService(string url, string classname, string methodname, object[] args)
{
//string @namespace = "EnterpriseServerBase.WebService.DynamicWebCalling";
string @namespace = "EnterpriseServerBase.WebService.DynamicWebCalling";
if ((classname == null) || (classname == ""))
{
classname = AddWebServices.GetWsClassName(url);
}
try
{ //获取WSDL
WebClient wc = new WebClient();
Stream stream = wc.OpenRead(url + "?WSDL");
ServiceDescription sd = ServiceDescription.Read(stream);
ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();
sdi.AddServiceDescription(sd, "", "");
CodeNamespace cn = new CodeNamespace(@namespace);
//生成客户端代理类代码
CodeCompileUnit ccu = new CodeCompileUnit();
ccu.Namespaces.Add(cn);
sdi.Import(cn, ccu);
CSharpCodeProvider icc = new CSharpCodeProvider();
//设定编译参数
CompilerParameters cplist = new CompilerParameters();
cplist.GenerateExecutable = false;
cplist.GenerateInMemory = true;
cplist.ReferencedAssemblies.Add("System.dll");
cplist.ReferencedAssemblies.Add("System.XML.dll");
cplist.ReferencedAssemblies.Add("System.Web.Services.dll");
cplist.ReferencedAssemblies.Add("System.Data.dll");
//编译代理类
CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu);
if (true == cr.Errors.HasErrors)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors)
{
sb.Append(ce.ToString());
sb.Append(System.Environment.NewLine);
}
throw new Exception(sb.ToString());
}
//生成代理实例,并调用方法
System.Reflection.Assembly assembly = cr.CompiledAssembly;
Type t = assembly.GetType(@namespace + "." + classname, true, true);
object obj = Activator.CreateInstance(t);
System.Reflection.MethodInfo mi = t.GetMethod(methodname);
return mi.Invoke(obj, args);
// PropertyInfo propertyInfo = type.GetProperty(propertyname);
//return propertyInfo.GetValue(obj, null);
}
catch (Exception ex)
{
throw new Exception(ex.InnerException.Message, new Exception(ex.InnerException.StackTrace));
}
}
private static string GetWsClassName(string wsUrl)
{
string[] parts = wsUrl.Split('/');
string[] pps = parts[parts.Length - 1].Split('.');
return pps[0];
} //上面那种方法的调用方式
//string url = "http://webservice.webxml.com.cn/WebServices/TrainTimeWebService.asmx";
//string[] args = new string[2];
//args[0] = "k123";
//args[1] = "";
//object result = WSHelper.InvokeWebService(url, "getDetailInfoByTrainCode", args);
//DataSet ds = (DataSet)result;
//this.GridView1.DataSource = ds;
//this.GridView1.DataBind();
}
}

关于C#调用WebServices的方法的更多相关文章

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

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

  2. jquery Ajax跨域调用WebServices方法

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

  3. asp.net 手工调用 WS(Get)方法:

    asp.net 手工调用 WS(Get)方法: 通过手工HttpWebRequest,HttpWebResponse来模拟调用.核心代码:string strurl="http://loca ...

  4. C# 通过Get、Post、Soap调用WebService的方法

    实现代码来源于网络,我只是作了一些修改! using System; using System.Web; using System.Xml; using System.Collections; usi ...

  5. WebService 调用三种方法

    //来源:http://www.cnblogs.com/eagle1986/archive/2012/09/03/2669699.html 最近做一个项目,由于是在别人框架里开发app,导致了很多限制 ...

  6. Java调用.NET webservice方法的几种方式

    最近做项目,涉及到web-service调用,现学了一个星期,现简单的做一个小结.下面实现的是对传喜物流系统(http://vip.cxcod.com/PodApi/GetPodStr.asmx?ws ...

  7. c#调用webservices

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

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

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

  9. c# 调用 webservices (转载)

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

随机推荐

  1. c# 向驱动打印机发送命令打开钱箱

    引用的dll 链接: https://pan.baidu.com/s/1MjwmfvBCPTBq1QNapKzDmg 提取码: 9wuf [DllImport("Drawcash.dll&q ...

  2. ubuntu QT开发环境(三种方法安装Qt4.8,其中apt-get方法安装QT库最简单)good

    方法一 QT4.8.0库+QT Creator 2.4.1 特别声明:此方法极其耗时间,看电脑性能了.配置configure可减少编译时间 1.下载Qt .进入网址http://qt.nokia.co ...

  3. DIOCP3 DEMO的编译(去掉VCL前缀)

    总有些朋友问我,关于DEMO编译的一些问题,每次都回答大概都差不多,我想还是写篇说明书给大家,关于DEMO编译的步骤. [环境设定] 1.将DIOCP3\source路径添加到Delphi的搜索路径, ...

  4. 台电P89s mini root教程

    根据论坛内的一些内容再结合自己的使用心得整理如下,本人双11购入P89s mini root成功  自带软件什么的都不见了 以下是个人root过程,有不一样的地方欢迎交流,说实话我也不是很懂 1.升级 ...

  5. uni-app中Vuex的引用

    //store 中 store.js import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) const store = new Vue ...

  6. Hive学习之路(一)—— Hive 简介及核心概念

    一.简介 Hive是一个构建在Hadoop之上的数据仓库,它可以将结构化的数据文件映射成表,并提供类SQL查询功能,用于查询的SQL语句会被转化为MapReduce作业,然后提交到Hadoop上运行. ...

  7. C语言实现贪吃蛇

    日期:2018.9.11 用时:150min 项目:贪吃蛇(C语言--数组   结构体实现) 开发工具:vs2013 关键知识:数组,结构体,图形库,键位操作 源代码: #include<std ...

  8. Linux运维工程师学习成长路线

    不过大家的留言都很精彩,希望大家也可以去留言区逛一逛~~ 好在这不是最后一期送书,之前已经有了好多活动,小编一定继续为大家多送些福利. 希望大家可以一如既往的关注脚本之家,支持爱你们的小编,共同进步! ...

  9. JS处理时间戳、前台拿到日期时间戳,时间戳转日期格式

    今晚做分页的时候,遇到后台往前台传日期类型,会出现这种情况,好像是微软为了解决操作系统兼容性问题,将日期全部转换为从1970年1月1日至现在时间的时间戳.为了解决这个问题,特意百度了一番,整理了处理日 ...

  10. Codeforces Gym101257F:Islands II(求割点+思维)

    http://codeforces.com/gym/101257/problem/F 题意:给出一个n*m的地图,上面相同数字的代表一个国家,问对于每个国家有多少个国家在它内部(即被包围).例如第一个 ...