最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【未解决】C#中如何调用wsdl的服务接口

接口 crifan 2450浏览 0评论
之前已经:
【调研】windows 服务器 接口 开发
想要实现:
写代码和接口去调用wsdl的接口
先去:
【未解决】Windows中用Visual Studio 2017去搭建一个wsdl的服务器端
C# 调用 wsdl
C# 调用WebService的3种方式 :直接调用、根据wsdl生成webservice的.cs文件及生成dll调用、动态调用 – jhlong – 博客园
C#.NET调用WSDL接口及方法 – hugaozhuang的专栏 – CSDN博客
“1.首先需要清楚WSDL的引用地址
  如:http://XX.XX.4.146:8089/axis/services/getfileno?wsdl
C#/Java 调用WSDL接口及方法 – zoey的专栏 – CSDN博客
“1.首先需要清楚WSDL的引用地址
  如:http://www.webxml.com.cn/Webservices/WeatherWebService.asmx
C#调用webservice接口的最新方法教程_C#教程_脚本之家
期间发现:
其实自己目的只是:想办法能搞懂如何C#中调用wsdl接口
how call wsdl in C#
how to call wsdl webservice in c# when request is xml and will return xml as response
c# – Client to send SOAP request and received response – Stack Overflow
c# – Sending and receiving SOAP messages – Stack Overflow
c# – how to get the xml representation of the SOAP request message? – Stack Overflow
从:
【调研】trffweb/services/TmriOutAccess?wsdl 相关资料
中了解到:
调用远程wsdl
是可以先用wsdl工具去生成代码
然后再去改url就可以继续调用了
在c#中通过http对象编程实现webservice调用 – http-string-c# – ItBoth
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);
        }
    }
【黑马Android】(14)webservice概念/调用/wsdl接口 – webservice-android-wsdl – ItBoth
“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的接口
WEB服务(Web Servicrs)| 免费WEB服务 | 商业WEB服务 | XML Web Servicrs – WEBXML
比如:
ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl
http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl
queryObjectOut
queryObjectOut C#
C# Web Service 如何调用-CSDN论坛
C#动态调用WebService方法之WS代理 – 幽兰上神 – CSDN博客
C# how call wsdl queryObjectOut
asp.net – Consuming a WSDL WebService from a DLL in C# using Visual Studio 2012 – Stack Overflow
https://stackoverflow.com/questions/32855539/consuming-a-wsdl-webservice-from-a-dll-in-c-sharp-using-visual-studio-2012
好像按照这个步骤就可以了:
调用wsdl接口中的方法了?
wcf – Consume webservice in c# with only wsdl – Stack Overflow
也很像这个:
C# Console App – Can’t retrieve SOAP 1.2 response from Web Service
以及:
c# – Client to send SOAP request and received response – Stack Overflow
asp.net – How to generate a WSDL file of a web service in Visual Studio – Stack Overflow
https://stackoverflow.com/questions/16186129/how-to-generate-a-wsdl-file-of-a-web-service-in-visual-studio
好像还是:
打开
xxx.asmx?WSDL
后,会下载到一个wsdl的xml文件
然后C#的.NET 项目中去引用这个web-reference的xml
https://stackoverflow.com/questions/46781656/how-to-get-the-xml-representation-of-the-soap-request-message
-》
The World’s Most Popular API Testing Tool | SoapUI
好像很不错的样子:
“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的服务接口

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
80 queries in 0.184 seconds, using 22.10MB memory