1. 程式人生 > >C# 動態呼叫wsdl WebService

C# 動態呼叫wsdl WebService

呼叫:wsdl Email地址驗證 WEB 服務,通過查詢給定的電子郵件域的郵件伺服器和通過向郵件伺服器傳送資料來判斷電子郵件地址正確與否


<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://WebXml.com.cn/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://WebXml.com.cn/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">&lt;a href="http://www.webxml.com.cn/" target="_blank"&gt;WebXml.com.cn&lt;/a&gt; &lt;strong&gt;Email地址驗證 WEB 服務&lt;/strong&gt;,通過查詢給定的電子郵件域的郵件伺服器和通過向郵件伺服器傳送資料來判斷電子郵件地址正確與否。此Email地址驗證Web Service請不要用於任何商業目的,若有需要請&lt;a href="http://www.webxml.com.cn/zh_cn/contact_us.aspx" target="_blank"&gt;聯絡我們&lt;/a&gt;,歡迎技術交流。 QQ:8409035&lt;br /&gt;&lt;strong&gt;使用本站 WEB 服務請註明或連結本站:http://www.webxml.com.cn/ 感謝大家的支援&lt;/strong&gt;!&lt;br /&gt;&lt;br /&gt;&amp;nbsp;</wsdl:documentation>
  <wsdl:types>
    <s:schema elementFormDefault="qualified" targetNamespace="http://WebXml.com.cn/">
      <s:element name="ValidateEmailAddress">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="theEmail" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="ValidateEmailAddressResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="ValidateEmailAddressResult" type="s:unsignedByte" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="ValidateEmailAddressPro">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="theEmail" type="s:string" />
            <s:element minOccurs="1" maxOccurs="1" name="theEmailPort" type="s:int" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="ValidateEmailAddressProResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="ValidateEmailAddressProResult" type="s:unsignedByte" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="unsignedByte" type="s:unsignedByte" />
    </s:schema>
  </wsdl:types>
  <wsdl:message name="ValidateEmailAddressSoapIn">
    <wsdl:part name="parameters" element="tns:ValidateEmailAddress" />
  </wsdl:message>
  <wsdl:message name="ValidateEmailAddressSoapOut">
    <wsdl:part name="parameters" element="tns:ValidateEmailAddressResponse" />
  </wsdl:message>
  <wsdl:message name="ValidateEmailAddressProSoapIn">
    <wsdl:part name="parameters" element="tns:ValidateEmailAddressPro" />
  </wsdl:message>
  <wsdl:message name="ValidateEmailAddressProSoapOut">
    <wsdl:part name="parameters" element="tns:ValidateEmailAddressProResponse" />
  </wsdl:message>
  <wsdl:message name="ValidateEmailAddressHttpGetIn">
    <wsdl:part name="theEmail" type="s:string" />
  </wsdl:message>
  <wsdl:message name="ValidateEmailAddressHttpGetOut">
    <wsdl:part name="Body" element="tns:unsignedByte" />
  </wsdl:message>
  <wsdl:message name="ValidateEmailAddressProHttpGetIn">
    <wsdl:part name="theEmail" type="s:string" />
    <wsdl:part name="theEmailPort" type="s:string" />
  </wsdl:message>
  <wsdl:message name="ValidateEmailAddressProHttpGetOut">
    <wsdl:part name="Body" element="tns:unsignedByte" />
  </wsdl:message>
  <wsdl:message name="ValidateEmailAddressHttpPostIn">
    <wsdl:part name="theEmail" type="s:string" />
  </wsdl:message>
  <wsdl:message name="ValidateEmailAddressHttpPostOut">
    <wsdl:part name="Body" element="tns:unsignedByte" />
  </wsdl:message>
  <wsdl:message name="ValidateEmailAddressProHttpPostIn">
    <wsdl:part name="theEmail" type="s:string" />
    <wsdl:part name="theEmailPort" type="s:string" />
  </wsdl:message>
  <wsdl:message name="ValidateEmailAddressProHttpPostOut">
    <wsdl:part name="Body" element="tns:unsignedByte" />
  </wsdl:message>
  <wsdl:portType name="ValidateEmailWebServiceSoap">
    <wsdl:operation name="ValidateEmailAddress">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">&lt;br /&gt;&lt;h3&gt;驗證 Email 地址是否正確&lt;/h3&gt;&lt;p&gt;輸入引數:EmailAddress = Email 地址(預設SMTP埠25),返回資料: Byte 位元組。返回值: 0 = 請重新驗證;1 = 郵件地址合法;2 = 只是域名正確;3 = 一個未知錯誤;4 = 郵件伺服器沒有找到;5 = 電子郵件地址錯誤;6 = 免費使用者驗證超過數量(50次/24小時);7 = 商業使用者不能通過驗證&lt;/p&gt;&lt;br /&gt;</wsdl:documentation>
      <wsdl:input message="tns:ValidateEmailAddressSoapIn" />
      <wsdl:output message="tns:ValidateEmailAddressSoapOut" />
    </wsdl:operation>
    <wsdl:operation name="ValidateEmailAddressPro">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">&lt;br /&gt;&lt;h3&gt;驗證 Email 地址是否正確&lt;/h3&gt;&lt;p&gt;輸入引數:EmailAddress = Email 地址,theEmailPort = SMTP埠(Integer),返回資料: Byte 位元組。返回值同 ValidateEmailAddress&lt;/p&gt;&lt;br /&gt;</wsdl:documentation>
      <wsdl:input message="tns:ValidateEmailAddressProSoapIn" />
      <wsdl:output message="tns:ValidateEmailAddressProSoapOut" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:portType name="ValidateEmailWebServiceHttpGet">
    <wsdl:operation name="ValidateEmailAddress">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">&lt;br /&gt;&lt;h3&gt;驗證 Email 地址是否正確&lt;/h3&gt;&lt;p&gt;輸入引數:EmailAddress = Email 地址(預設SMTP埠25),返回資料: Byte 位元組。返回值: 0 = 請重新驗證;1 = 郵件地址合法;2 = 只是域名正確;3 = 一個未知錯誤;4 = 郵件伺服器沒有找到;5 = 電子郵件地址錯誤;6 = 免費使用者驗證超過數量(50次/24小時);7 = 商業使用者不能通過驗證&lt;/p&gt;&lt;br /&gt;</wsdl:documentation>
      <wsdl:input message="tns:ValidateEmailAddressHttpGetIn" />
      <wsdl:output message="tns:ValidateEmailAddressHttpGetOut" />
    </wsdl:operation>
    <wsdl:operation name="ValidateEmailAddressPro">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">&lt;br /&gt;&lt;h3&gt;驗證 Email 地址是否正確&lt;/h3&gt;&lt;p&gt;輸入引數:EmailAddress = Email 地址,theEmailPort = SMTP埠(Integer),返回資料: Byte 位元組。返回值同 ValidateEmailAddress&lt;/p&gt;&lt;br /&gt;</wsdl:documentation>
      <wsdl:input message="tns:ValidateEmailAddressProHttpGetIn" />
      <wsdl:output message="tns:ValidateEmailAddressProHttpGetOut" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:portType name="ValidateEmailWebServiceHttpPost">
    <wsdl:operation name="ValidateEmailAddress">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">&lt;br /&gt;&lt;h3&gt;驗證 Email 地址是否正確&lt;/h3&gt;&lt;p&gt;輸入引數:EmailAddress = Email 地址(預設SMTP埠25),返回資料: Byte 位元組。返回值: 0 = 請重新驗證;1 = 郵件地址合法;2 = 只是域名正確;3 = 一個未知錯誤;4 = 郵件伺服器沒有找到;5 = 電子郵件地址錯誤;6 = 免費使用者驗證超過數量(50次/24小時);7 = 商業使用者不能通過驗證&lt;/p&gt;&lt;br /&gt;</wsdl:documentation>
      <wsdl:input message="tns:ValidateEmailAddressHttpPostIn" />
      <wsdl:output message="tns:ValidateEmailAddressHttpPostOut" />
    </wsdl:operation>
    <wsdl:operation name="ValidateEmailAddressPro">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">&lt;br /&gt;&lt;h3&gt;驗證 Email 地址是否正確&lt;/h3&gt;&lt;p&gt;輸入引數:EmailAddress = Email 地址,theEmailPort = SMTP埠(Integer),返回資料: Byte 位元組。返回值同 ValidateEmailAddress&lt;/p&gt;&lt;br /&gt;</wsdl:documentation>
      <wsdl:input message="tns:ValidateEmailAddressProHttpPostIn" />
      <wsdl:output message="tns:ValidateEmailAddressProHttpPostOut" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="ValidateEmailWebServiceSoap" type="tns:ValidateEmailWebServiceSoap">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="ValidateEmailAddress">
      <soap:operation soapAction="http://WebXml.com.cn/ValidateEmailAddress" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="ValidateEmailAddressPro">
      <soap:operation soapAction="http://WebXml.com.cn/ValidateEmailAddressPro" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:binding name="ValidateEmailWebServiceSoap12" type="tns:ValidateEmailWebServiceSoap">
    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="ValidateEmailAddress">
      <soap12:operation soapAction="http://WebXml.com.cn/ValidateEmailAddress" style="document" />
      <wsdl:input>
        <soap12:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="ValidateEmailAddressPro">
      <soap12:operation soapAction="http://WebXml.com.cn/ValidateEmailAddressPro" style="document" />
      <wsdl:input>
        <soap12:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:binding name="ValidateEmailWebServiceHttpGet" type="tns:ValidateEmailWebServiceHttpGet">
    <http:binding verb="GET" />
    <wsdl:operation name="ValidateEmailAddress">
      <http:operation location="/ValidateEmailAddress" />
      <wsdl:input>
        <http:urlEncoded />
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="ValidateEmailAddressPro">
      <http:operation location="/ValidateEmailAddressPro" />
      <wsdl:input>
        <http:urlEncoded />
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:binding name="ValidateEmailWebServiceHttpPost" type="tns:ValidateEmailWebServiceHttpPost">
    <http:binding verb="POST" />
    <wsdl:operation name="ValidateEmailAddress">
      <http:operation location="/ValidateEmailAddress" />
      <wsdl:input>
        <mime:content type="application/x-www-form-urlencoded" />
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="ValidateEmailAddressPro">
      <http:operation location="/ValidateEmailAddressPro" />
      <wsdl:input>
        <mime:content type="application/x-www-form-urlencoded" />
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="ValidateEmailWebService">
    <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">&lt;a href="http://www.webxml.com.cn/" target="_blank"&gt;WebXml.com.cn&lt;/a&gt; &lt;strong&gt;Email地址驗證 WEB 服務&lt;/strong&gt;</wsdl:documentation>
    <wsdl:port name="ValidateEmailWebServiceSoap" binding="tns:ValidateEmailWebServiceSoap">
      <soap:address location="http://www.webxml.com.cn/WebServices/ValidateEmailWebService.asmx" />
    </wsdl:port>
    <wsdl:port name="ValidateEmailWebServiceSoap12" binding="tns:ValidateEmailWebServiceSoap12">
      <soap12:address location="http://www.webxml.com.cn/WebServices/ValidateEmailWebService.asmx" />
    </wsdl:port>
    <wsdl:port name="ValidateEmailWebServiceHttpGet" binding="tns:ValidateEmailWebServiceHttpGet">
      <http:address location="http://www.webxml.com.cn/WebServices/ValidateEmailWebService.asmx" />
    </wsdl:port>
    <wsdl:port name="ValidateEmailWebServiceHttpPost" binding="tns:ValidateEmailWebServiceHttpPost">
      <http:address location="http://www.webxml.com.cn/WebServices/ValidateEmailWebService.asmx" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

呼叫類讀取WSDL

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;


using System.IO;
using System.Net;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Web.Services.Description;
using System.Xml.Serialization;
using System.Web.Services.Discovery;
using System.Xml.Schema;
using System.Text;
using System.Security.Cryptography;
using System.Reflection;
using System.Collections.Generic;
using System.Xml;  

namespace WindowsFormsApplication1
{
    #region 利用WebService呼叫類
    /// <summary>
    ///  利用WebRequest/WebResponse進行WebService呼叫的類
    /// </summary>
    public class WebSvcCaller
    {
        //<webServices>
        //  <protocols>
        //    <add name="HttpGet"/>
        //    <add name="HttpPost"/>
        //  </protocols>
        //</webServices>
        private static Hashtable _xmlNamespaces = new Hashtable();//快取xmlNamespace,避免重複呼叫GetNamespace

        /// <summary>
        /// 需要WebService支援Post呼叫
        /// </summary>
        public static XmlDocument QueryPostWebService(String URL, String MethodName, Hashtable Pars)
        {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL + "/" + MethodName);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            SetWebRequest(request);
            byte[] data = EncodePars(Pars);
            WriteRequestData(request, data);
            return ReadXmlResponse(request.GetResponse());
        }

        /// <summary>
        /// 需要WebService支援Get呼叫
        /// </summary>
        public static XmlDocument QueryGetWebService(String URL, String MethodName, Hashtable Pars)
        {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL + "/" + MethodName + "?" + ParsToString(Pars));
            request.Method = "GET";
            request.ContentType = "application/x-www-form-urlencoded";
            SetWebRequest(request);
            return ReadXmlResponse(request.GetResponse());
        }


        /// <summary>
        /// 通用WebService呼叫(Soap),引數Pars為String型別的引數名、引數值
        /// </summary>
        public static XmlDocument QuerySoapWebService(String URL, String MethodName, Hashtable Pars)
        {
            if (_xmlNamespaces.ContainsKey(URL))
            {
                return QuerySoapWebService(URL, MethodName, Pars, _xmlNamespaces[URL].ToString());
            }
            else
            {
                return QuerySoapWebService(URL, MethodName, Pars, GetNamespace(URL));
            }
        }
        private static XmlDocument QuerySoapWebService(String URL, String MethodName, Hashtable Pars, string XmlNs)
        {
            _xmlNamespaces[URL] = 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 + "\"");
            SetWebRequest(request);
            byte[] data = EncodeParsToSoap(Pars, XmlNs, MethodName);
            WriteRequestData(request, data);
            XmlDocument doc = new XmlDocument(), doc2 = new XmlDocument();
            doc = ReadXmlResponse(request.GetResponse());
            XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable);
            mgr.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
            String RetXml = doc.SelectSingleNode("//soap:Body/*/*", mgr).InnerXml;
            doc2.LoadXml("<root>" + RetXml + "</root>");
            AddDelaration(doc2);
            return doc2;
        }
        private static string GetNamespace(String URL)
        {
            string sURL = URL; string sResult = "";
            if (URL.IndexOf("?") < 0)
            {
                sURL = URL + "?WSDL";
            }

            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sURL);
                SetWebRequest(request);
                WebResponse response = request.GetResponse();
                StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(sr.ReadToEnd());
                sr.Close();
                sResult = doc.SelectSingleNode("//@targetNamespace").Value;
            }
            catch
            {

            }
            return sResult;
        }
        private static byte[] EncodeParsToSoap(Hashtable Pars, 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>");
            AddDelaration(doc);

            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 Pars.Keys)
            {
                XmlElement soapPar = doc.CreateElement(k);
                soapPar.InnerXml = ObjectToSoapXml(Pars[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();
            }
        }
        private static void SetWebRequest(HttpWebRequest request)
        {
            request.Credentials = CredentialCache.DefaultCredentials;
            request.Timeout = 10000;
        }
        private static void WriteRequestData(HttpWebRequest request, byte[] data)
        {
            request.ContentLength = data.Length;
            Stream writer = request.GetRequestStream();
            writer.Write(data, 0, data.Length);
            writer.Close();
        }
        private static byte[] EncodePars(Hashtable Pars)
        {
            return Encoding.UTF8.GetBytes(ParsToString(Pars));
        }
        private static String ParsToString(Hashtable Pars)
        {
            StringBuilder sb = new StringBuilder();
            foreach (string k in Pars.Keys)
            {
                if (sb.Length > 0)
                {
                    sb.Append("&");
                }
                //sb.Append(HttpUtility.UrlEncode(k) + "=" + HttpUtility.UrlEncode(Pars[k].ToString()));
            }
            return sb.ToString();
        }
        private static XmlDocument ReadXmlResponse(WebResponse response)
        {
            StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
            String retXml = sr.ReadToEnd();
            sr.Close();
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(retXml);
            return doc;
        }
        private static void AddDelaration(XmlDocument doc)
        {
            XmlDeclaration decl = doc.CreateXmlDeclaration("1.0", "utf-8", null);
            doc.InsertBefore(decl, doc.DocumentElement);
        }
    }

    #endregion
}

  Hashtable ht = new Hashtable();
   ht.Add("theEmail", "[email protected]");
    XmlDocument xdoc = WebSvcCaller.QuerySoapWebService(textBox1.Text, "ValidateEmailAddress", ht);

  this.textBox2.Text = xdoc.InnerText;

相關推薦

C# 動態呼叫wsdl WebService

呼叫:wsdl Email地址驗證 WEB 服務,通過查詢給定的電子郵件域的郵件伺服器和通過向郵件伺服器傳送資料來判斷電子郵件地址正確與否 <?xml version="1.0" encoding="utf-8"?> <wsdl:definition

C#動態呼叫webservice的方法

轉載自http://blog.sina.com.cn/s/blog_5d25ac4e0100yiel.html 一般情況下winform呼叫webservice時步驟 1新增服務引用---高階----新增web引用------填寫url--新增web引用即可完成對w

C#動態呼叫WebService方法之WS代理

通常我們在程式中需要呼叫WebService時,都是通過“新增Web引用”,讓VS.NET環境來為我們生成服務代理,然後呼叫對應的Web服務。這樣是使工作簡單了,但是卻和提供Web服務的URL、方法名、引數繫結在一起了,這是VS.NET自動為我們生成Web服務代理的限制。

C# 動態調用 webservice 的類

方法 lin 命名空間 urn ins AR HR ces 地址 封裝這個類是為之後使用 webservice 不用添加各種引用了。 using System; using System.Collections.Generic; using System.Comp

C#動態呼叫C++編寫的DLL函式

C#動態呼叫C++編寫的DLL函式 動態載入DLL需要使用Windows API函式:LoadLibrary、GetProcAddress以及FreeLibrary。我們可以使用DllImport在C#中使用這三個函式。 [DllImport(“Kernel32”)] publ

object-c動態呼叫

  採用遞迴的方法訪問一個物件,講其內容寫到一個字典中 支援的成員變數型別: 1,NSString * 2,NSArray * 3,由1,2,構成的自定義類 + (NSMutableDictionary *) getDicFromObject: (id) th

C# 動態呼叫泛型方法

static void Main(string[] args) { #region 具體型別可傳遞。 Personal specifiedPersonal = new Personal(); Employe

C#動態呼叫帶有SoapHeader驗證的WebServices

本文記錄C#中通過反射動態的呼叫帶有SoapHeader驗證的WebServices服務,基於 Windows8.1、Visual Studio 2013、IIS8 環境實現。 關於WebService建立、部署及靜態呼叫等內容,可以見:C#靜態呼叫帶有SoapHeader驗證的Web

C#.NET呼叫WSDL介面及方法

1.首先需要清楚WSDL的引用地址   上述地址的構造為 類名getfileno。 2.在.Net專案中,新增web引用。 3.在彈出頁面中,點選前往按鈕。 4.將web引用名 進行自定義填寫即可。 效果如圖所示: 5.在專案中引用wsdl中的方法。  

C函式的DLL,C++動態呼叫

1、專案結構 2、建立c專案,其實很簡單,只要原始檔是.c的即可。 CDLL.h標頭檔案 #ifndef __CDLL_H__ #define __CDLL_H__ extern int

C#動態呼叫C++的Dll

C#動態呼叫C++的Dll函式 1.動態呼叫dll需要使用LoadLibrary, GetProcAddress, FreeLibrary 3個系統的API函式,所以在C#中用一個類靜態呼叫kernal32.dl. 如下: class  DllTest { // 呼叫API庫

C# 動態呼叫DLL庫

最近經常用到C#動態呼叫類庫,簡單的做下記錄方便以後查詢。 使用下面的幾行程式碼就可以簡單實現DLL類庫的呼叫了 using System.Reflection; // 引入該名稱空間 // 獲取

C# 呼叫WebService的3種方式 :直接呼叫、根據wsdl生成webservice的.cs檔案及生成dll呼叫動態呼叫

1.直接呼叫 已知webservice路徑,則可以直接 新增服務引用--高階--新增web引用 直接輸入webservice URL。這個比較常見也很簡單 即有完整的webservice檔案目錄如下圖所示, 也可以在本地IIS根據webservice檔案目錄新發佈一個webserv

轉載:動態呼叫WebService(C#)

         #region InvokeWebService // 動態呼叫web服務 public static object InvokeWebService( string url, string methodname, object

Net 下采用GET/POST/SOAP方式動態呼叫WebService C#實現

 一直以來,我們都為動態呼叫WebService方法而煩惱。在.Net環境下,最常用的方法就是採用代理類來呼叫WebService,可以通過改變代理類的Url屬性來實現動態呼叫,但當xmlns改變時就會出錯,似乎要重新繫結Webservice並重新編譯後才能再次執行。我

C#不新增引用,動態呼叫webservice

好像很多人做WebService的時候都是直接新增引用的方式,然後呼叫服務端的方法。這樣就個問題,就是每次我服務端添加了方法或者修改了方法後都要更新Web引用,這樣比較麻煩。下面給一個不用新增引用的方式呼叫服務端的方法

C# 之 動態呼叫WebService

通過前一篇部落格《WCF 之 AJax前臺呼叫WCF服務》我們可以不用配置終結點,而且可以動態的呼叫WCF服務。但是我們不僅僅要會動態的呼叫WCF服務,同時也需要研究一下怎麼樣動態的呼叫Web Service,今天就給大家介紹一下。 首先,我們先建立兩個Web Serv

C# 三種動態呼叫WebService的方法,測試通過

廢話少說,直接上碼: Python 伺服器端: import soaplib from soaplib.service import rpc from soaplib.service import DefinitionBase from soaplib.model.pr

C#中Winform動態呼叫Webservice的方法

一般情況下winform呼叫webservice時步驟 1新增服務引用---高階----新增web引用------填寫url--新增web引用即可完成對webservice的引用 讓VS.NET環境來為我們生成服務代理,然後呼叫對應的Web服務。 如果需要動態呼叫WebSe

C#呼叫WebService服務(動態呼叫)

1 建立WebService using System;   using System.Web.Services;   namespace WebService1   {       /// <summary>     /// Service1 的摘要說明