之前已经:
【调研】windows 服务器 接口 开发
想要实现:
写代码和接口去调用wsdl的接口
先去:
【未解决】Windows中用Visual Studio 2017去搭建一个wsdl的服务器端
C# 调用 wsdl
“1.首先需要清楚WSDL的引用地址
“1.首先需要清楚WSDL的引用地址
期间发现:
其实自己目的只是:想办法能搞懂如何C#中调用wsdl接口
how call wsdl in C#

how to call wsdl webservice in c# when request is xml and will return xml as response
从:
【调研】trffweb/services/TmriOutAccess?wsdl 相关资料
中了解到:
调用远程wsdl
是可以先用wsdl工具去生成代码
然后再去改url就可以继续调用了
1.webservice帮助类
---------------------------------------------------------------------------------------------------------------
public class WebServiceHelper
{
public static string CallServiceByGet(string strURL)
{
//string strURL = "http://localhost:12074/Service1.asmx/GetProductPrice?ProductId=";
//strURL += this.textBox1.Text;
//创建一个HTTP请求
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strURL);
//request.Method="get";
HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
Stream s = response.GetResponseStream();
//转化为XML,自己进行处理
XmlTextReader Reader = new XmlTextReader(s);
Reader.MoveToContent();
string strValue = Reader.ReadInnerXml();
Reader.Close();
strValue = strValue.Replace("<", "<");
strValue = strValue.Replace(">", ">");
return strValue;
}
public static string CallServiceByPost(string strURL,System.Collections.Specialized.StringDictionary parameters)
{
//string strURL = "http://localhost:12074/Service1.asmx/GetProductPrice";
//创建一个HTTP请求
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strURL);
//Post请求方式
request.Method = "POST";
//内容类型
request.ContentType = "application/x-www-form-urlencoded";
//设置参数,并进行URL编码
StringBuilder codedString = new StringBuilder();
foreach (string key in parameters.Keys)
{
codedString.Append(HttpUtility.UrlEncode(key));
codedString.Append("=");
codedString.Append(HttpUtility.UrlEncode(parameters[key]));
codedString.Append("&");
}
string paraUrlCoded = codedString.Length == 0 ? string.Empty:codedString.ToString().Substring(0, codedString.Length - 1);
//string paraUrlCoded = HttpUtility.UrlEncode("ProductId");
//paraUrlCoded += "=" + HttpUtility.UrlEncode(this.textBox1.Text);
byte[] payload;
//将URL编码后的字符串转化为字节
payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
//设置请求的ContentLength
request.ContentLength = payload.Length;
//发送请求,获得请求流
Stream writer = request.GetRequestStream();
//将请求参数写入流
writer.Write(payload, 0, payload.Length);
//关闭请求流
writer.Close();
//获得响应流
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream s = response.GetResponseStream();
//转化为XML,自己进行处理
XmlTextReader Reader = new XmlTextReader(s);
Reader.MoveToContent();
string strValue = Reader.ReadInnerXml();
Reader.Close();
strValue = strValue.Replace("<", "<");
strValue = strValue.Replace(">", ">");
return strValue;
}
}
---------------------------------------------------------------------------------------------------------------
2.webservice方法
---------------------------------------------------------------------------------------------------------------
/// <summary>
/// Service1 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld1()
{
return "Hello World";
}
[WebMethod]
public string HelloWorld2(string p1,string p2)
{
return string.Concat("Hello World", ",", p1, ",", p2);
}
[WebMethod]
public string HelloWorld3(string datetime)
{
return string.Concat("Hello World", " today is ", datetime);
}
}
“webservice 就是一个应用程序,它提供一种通过web方式访问的api.
解决两个系统或者(应用程序)之间的远程调用…..
调用是跨语言,跨平台…
webservice 最基本的组成部分就是客户端,服务端…
服务端:(作为服务端,怎么将自己的应用程序发布成一个webservice,让别人调用)
xml (webservice的客户端与服务端进行交互的时候传递的数据格式)
webservice description language(web服务描述语言.. api)xml,简称wsdl
soap(简单对象访问协议) webservice的客户端与服务端进行交互的时候走的协议
(soap 分两个版本(soap 1.1与soap1.2)),现在的版本是soap1.1,因为java jdk 只支持soap1.1版本的协议发布..
***** soap 协议=在http的基础之上传送xml格式的数据..”

-》
还真巧了找到了我想要的,某个wsdl的接口
比如:


queryObjectOut
queryObjectOut C#
C# how call wsdl queryObjectOut
asp.net – Consuming a WSDL WebService from a DLL in C# using Visual Studio 2012 – Stack Overflow
好像按照这个步骤就可以了:
调用wsdl接口中的方法了?
也很像这个:
以及:
asp.net – How to generate a WSDL file of a web service in Visual Studio – Stack Overflow
好像还是:
打开
xxx.asmx?WSDL
后,会下载到一个wsdl的xml文件
然后C#的.NET 项目中去引用这个web-reference的xml
-》
好像很不错的样子:
“Build Better | Test Smarter
The Most Advanced REST & SOAP Testing Tool in the World
The Complete API Test Automation Framework for SOAP, REST and More”
转载请注明:在路上 » 【未解决】C#中如何调用wsdl的服务接口