一起草最新网址_日韩一区二区麻豆国产_91视频婷婷_日本一区二区视频在线_日韩激情一区二区三区_国产另类第一区_成人免费在线播放视频_亚洲永久精品ww.7491进入_久久这里有精品视频_久久精品一级片_日韩av在线网页_波多野结衣不卡视频

深入.net調(diào)用webservice的總結(jié)分析_.Net教程

編輯Tag賺U幣

推薦:c#自定義控件中事件的處理
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace ClientControl { //1.定義委托 public delegate void NewsClickEventHandle(obj

最近做一個(gè)項(xiàng)目,由于是在別人框架里開(kāi)發(fā)app,導(dǎo)致了很多限制,其中一個(gè)就是不能直接引用webservice 。
我們都知道,調(diào)用webserivice 最簡(jiǎn)單的方法就是在 "引用" 那里點(diǎn)擊右鍵,然后選擇"引用web服務(wù)",再輸入服務(wù)地址。
確定后,會(huì)生成一個(gè)app.config 里面就會(huì)自動(dòng)生成了一些配置信息。
現(xiàn)在正在做的這個(gè)項(xiàng)目就不能這么干。后來(lái)經(jīng)過(guò)一番搜索,就找出另外幾種動(dòng)態(tài)調(diào)用webservice 的方法。
廢話少說(shuō),下面是webservice 代碼
復(fù)制代碼 代碼如下:www.zhaotila.cn

View Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace TestWebService
{
/// <summary>
/// Service1 的摘要說(shuō)明
/// </summary>
[WebService(Namespace = "http://tempuri.org/",Description="我的Web服務(wù)")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允許使用 ASP.NET AJAX 從腳本中調(diào)用此 Web 服務(wù),請(qǐng)取消對(duì)下行的注釋。
// [System.Web.Script.Services.ScriptService]
public class TestWebService : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "測(cè)試Hello World";
}
[WebMethod]
public string Test()
{
return "測(cè)試Test";
}

[WebMethod(CacheDuration = 60,Description = "測(cè)試")]
public List<String> GetPersons()
{
List<String> list = new List<string>();
list.Add("測(cè)試一");
list.Add("測(cè)試二");
list.Add("測(cè)試三");
return list;
}
}
}

動(dòng)態(tài)調(diào)用示例:
方法一:
看到很多動(dòng)態(tài)調(diào)用WebService都只是動(dòng)態(tài)調(diào)用地址而已,下面發(fā)一個(gè)不光是根據(jù)地址調(diào)用,方法名也可以自己指定的,主要原理是根據(jù)指定的WebService地址的WSDL,然后解析模擬生成一個(gè)代理類,通過(guò)反射調(diào)用里面的方法
復(fù)制代碼 代碼如下:www.zhaotila.cn

View Code
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using System.Web;
using System.Net;
using System.Reflection;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Web.Services;
using System.Text;
using System.Web.Services.Description;
using System.Web.Services.Protocols;
using System.Xml.Serialization;
using System.Windows.Forms;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
WebClient client = new WebClient();
String url = "http://localhost:3182/Service1.asmx?WSDL";//這個(gè)地址可以寫(xiě)在Config文件里面,這里取出來(lái)就行了.在原地址后面加上: ?WSDL
Stream stream = client.OpenRead(url);
ServiceDescription description = ServiceDescription.Read(stream);
ServiceDescriptionImporter importer = new ServiceDescriptionImporter();//創(chuàng)建客戶端代理代理類。
importer.ProtocolName = "Soap"; //指定訪問(wèn)協(xié)議。
importer.Style = ServiceDescriptionImportStyle.Client; //生成客戶端代理。
importer.CodeGenerationOptions = CodeGenerationOptions.GenerateProperties | CodeGenerationOptions.GenerateNewAsync;
importer.AddServiceDescription(description, null, null); //添加WSDL文檔。
CodeNamespace nmspace = new CodeNamespace(); //命名空間
nmspace.Name = "TestWebService";
CodeCompileUnit unit = new CodeCompileUnit();
unit.Namespaces.Add(nmspace);
ServiceDescriptionImportWarnings warning = importer.Import(nmspace, unit);
CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");
CompilerParameters parameter = new CompilerParameters();
parameter.GenerateExecutable = false;
parameter.OutputAssembly = "MyTest.dll";//輸出程序集的名稱
parameter.ReferencedAssemblies.Add("System.dll");
parameter.ReferencedAssemblies.Add("System.XML.dll");
parameter.ReferencedAssemblies.Add("System.Web.Services.dll");
parameter.ReferencedAssemblies.Add("System.Data.dll");
CompilerResults result = provider.CompileAssemblyFromDom(parameter, unit);
if (result.Errors.HasErrors)
{
// 顯示編譯錯(cuò)誤信息
}
Assembly asm = Assembly.LoadFrom("MyTest.dll");//加載前面生成的程序集
Type t = asm.GetType("TestWebService.TestWebService");
object o = Activator.CreateInstance(t);
MethodInfo method = t.GetMethod("GetPersons");//GetPersons是服務(wù)端的方法名稱,你想調(diào)用服務(wù)端的什么方法都可以在這里改,最好封裝一下
String[] item = (String[])method.Invoke(o, null);
//注:method.Invoke(o, null)返回的是一個(gè)Object,如果你服務(wù)端返回的是DataSet,這里也是用(DataSet)method.Invoke(o, null)轉(zhuǎn)一下就行了,method.Invoke(0,null)這里的null可以傳調(diào)用方法需要的參數(shù),string[]形式的
foreach (string str in item)
Console.WriteLine(str);
//上面是根據(jù)WebService地址,模似生成一個(gè)代理類,如果你想看看生成的代碼文件是什么樣子,可以用以下代碼保存下來(lái),默認(rèn)是保存在bin目錄下面
TextWriter writer = File.CreateText("MyTest.cs");
provider.GenerateCodeFromCompileUnit(unit, writer, null);
writer.Flush();
writer.Close();
}
}
}

方法二:利用 wsdl.exe生成webservice代理類:
根據(jù)提供的wsdl生成webservice代理類,然后在代碼里引用這個(gè)類文件。
步驟:
1、在開(kāi)始菜單找到 Microsoft Visual Studio 2010 下面的Visual Studio Tools , 點(diǎn)擊Visual Studio 命令提示(2010),打開(kāi)命令行。
2、 在命令行中輸入: wsdl /language:c# /n:TestDemo /out:d:/Temp/TestService.cs http://jm1.services.gmcc.net/ad/Services/AD.asmx?wsdl
這句命令行的意思是:對(duì)最后面的服務(wù)地址進(jìn)行編譯,在D盤temp 目錄下生成testservice文件。
3、 把上面命令編譯后的cs文件,復(fù)制到我們項(xiàng)目中,在項(xiàng)目代碼中可以直接new 一個(gè)出來(lái)后,可以進(jìn)行調(diào)用。
貼出由命令行編譯出來(lái)的代碼:
復(fù)制代碼 代碼如下:www.zhaotila.cn

View Code
//------------------------------------------------------------------------------
// <auto-generated>
// 此代碼由工具生成。
// 運(yùn)行時(shí)版本:4.0.30319.225
//
// 對(duì)此文件的更改可能會(huì)導(dǎo)致不正確的行為,并且如果
// 重新生成代碼,這些更改將會(huì)丟失。
// </auto-generated>
//------------------------------------------------------------------------------
//
// 此源代碼由 wsdl 自動(dòng)生成, Version=4.0.30319.1。
//
namespace Bingosoft.Module.SurveyQuestionnaire.DAL {
using System;
using System.Diagnostics;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Web.Services.Protocols;
using System.Web.Services;
using System.Data;


/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="WebserviceForILookSoap", Namespace="http://tempuri.org/")]
public partial class WebserviceForILook : System.Web.Services.Protocols.SoapHttpClientProtocol {

private System.Threading.SendOrPostCallback GetRecordNumOperationCompleted;

private System.Threading.SendOrPostCallback GetVoteListOperationCompleted;

private System.Threading.SendOrPostCallback VoteOperationCompleted;

private System.Threading.SendOrPostCallback GiveUpOperationCompleted;

private System.Threading.SendOrPostCallback GetQuestionTaskListOperationCompleted;

/// <remarks/>
public WebserviceForILook() {
this.Url = "http://st1.services.gmcc.net/qnaire/Services/WebserviceForILook.asmx";
}

/// <remarks/>
public event GetRecordNumCompletedEventHandler GetRecordNumCompleted;

/// <remarks/>
public event GetVoteListCompletedEventHandler GetVoteListCompleted;

/// <remarks/>
public event VoteCompletedEventHandler VoteCompleted;

/// <remarks/>
public event GiveUpCompletedEventHandler GiveUpCompleted;

/// <remarks/>
public event GetQuestionTaskListCompletedEventHandler GetQuestionTaskListCompleted;

/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/GetRecordNum", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public int[] GetRecordNum(string appcode, string userID) {
object[] results = this.Invoke("GetRecordNum", new object[] {
appcode,
userID});
return ((int[])(results[0]));
}

/// <remarks/>
public System.IAsyncResult BeginGetRecordNum(string appcode, string userID, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("GetRecordNum", new object[] {
appcode,
userID}, callback, asyncState);
}

/// <remarks/>
public int[] EndGetRecordNum(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((int[])(results[0]));
}

/// <remarks/>
public void GetRecordNumAsync(string appcode, string userID) {
this.GetRecordNumAsync(appcode, userID, null);
}

/// <remarks/>
public void GetRecordNumAsync(string appcode, string userID, object userState) {
if ((this.GetRecordNumOperationCompleted == null)) {
this.GetRecordNumOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetRecordNumOperationCompleted);
}
this.InvokeAsync("GetRecordNum", new object[] {
appcode,
userID}, this.GetRecordNumOperationCompleted, userState);
}

private void OnGetRecordNumOperationCompleted(object arg) {
if ((this.GetRecordNumCompleted != null)) {
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.GetRecordNumCompleted(this, new GetRecordNumCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
}
}

/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/GetVoteList", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public System.Data.DataSet GetVoteList(string appcode, string userID) {
object[] results = this.Invoke("GetVoteList", new object[] {
appcode,
userID});
return ((System.Data.DataSet)(results[0]));
}

/// <remarks/>
public System.IAsyncResult BeginGetVoteList(string appcode, string userID, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("GetVoteList", new object[] {
appcode,
userID}, callback, asyncState);
}

/// <remarks/>
public System.Data.DataSet EndGetVoteList(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((System.Data.DataSet)(results[0]));
}

/// <remarks/>
public void GetVoteListAsync(string appcode, string userID) {
this.GetVoteListAsync(appcode, userID, null);
}

/// <remarks/>
public void GetVoteListAsync(string appcode, string userID, object userState) {
if ((this.GetVoteListOperationCompleted == null)) {
this.GetVoteListOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetVoteListOperationCompleted);
}
this.InvokeAsync("GetVoteList", new object[] {
appcode,
userID}, this.GetVoteListOperationCompleted, userState);
}

private void OnGetVoteListOperationCompleted(object arg) {
if ((this.GetVoteListCompleted != null)) {
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.GetVoteListCompleted(this, new GetVoteListCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
}
}

/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/Vote", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public bool Vote(string appcode, string userID, string qTaskID, string answer) {
object[] results = this.Invoke("Vote", new object[] {
appcode,
userID,
qTaskID,
answer});
return ((bool)(results[0]));
}

/// <remarks/>
public System.IAsyncResult BeginVote(string appcode, string userID, string qTaskID, string answer, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("Vote", new object[] {
appcode,
userID,
qTaskID,
answer}, callback, asyncState);
}

/// <remarks/>
public bool EndVote(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((bool)(results[0]));
}

/// <remarks/>
public void VoteAsync(string appcode, string userID, string qTaskID, string answer) {
this.VoteAsync(appcode, userID, qTaskID, answer, null);
}

/// <remarks/>
public void VoteAsync(string appcode, string userID, string qTaskID, string answer, object userState) {
if ((this.VoteOperationCompleted == null)) {
this.VoteOperationCompleted = new System.Threading.SendOrPostCallback(this.OnVoteOperationCompleted);
}
this.InvokeAsync("Vote", new object[] {
appcode,
userID,
qTaskID,
answer}, this.VoteOperationCompleted, userState);
}

private void OnVoteOperationCompleted(object arg) {
if ((this.VoteCompleted != null)) {
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.VoteCompleted(this, new VoteCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
}
}

/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/GiveUp", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public bool GiveUp(string appcode, string userID, string qTaskID) {
object[] results = this.Invoke("GiveUp", new object[] {
appcode,
userID,
qTaskID});
return ((bool)(results[0]));
}

/// <remarks/>
public System.IAsyncResult BeginGiveUp(string appcode, string userID, string qTaskID, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("GiveUp", new object[] {
appcode,
userID,
qTaskID}, callback, asyncState);
}

/// <remarks/>
public bool EndGiveUp(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((bool)(results[0]));
}

/// <remarks/>
public void GiveUpAsync(string appcode, string userID, string qTaskID) {
this.GiveUpAsync(appcode, userID, qTaskID, null);
}

/// <remarks/>
public void GiveUpAsync(string appcode, string userID, string qTaskID, object userState) {
if ((this.GiveUpOperationCompleted == null)) {
this.GiveUpOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGiveUpOperationCompleted);
}
this.InvokeAsync("GiveUp", new object[] {
appcode,
userID,
qTaskID}, this.GiveUpOperationCompleted, userState);
}

private void OnGiveUpOperationCompleted(object arg) {
if ((this.GiveUpCompleted != null)) {
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.GiveUpCompleted(this, new GiveUpCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
}
}

/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/GetQuestionTaskList", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public System.Data.DataSet GetQuestionTaskList(string appcode, string userID) {
object[] results = this.Invoke("GetQuestionTaskList", new object[] {
appcode,
userID});
return ((System.Data.DataSet)(results[0]));
}

/// <remarks/>
public System.IAsyncResult BeginGetQuestionTaskList(string appcode, string userID, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("GetQuestionTaskList", new object[] {
appcode,
userID}, callback, asyncState);
}

/// <remarks/>
public System.Data.DataSet EndGetQuestionTaskList(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((System.Data.DataSet)(results[0]));
}

/// <remarks/>
public void GetQuestionTaskListAsync(string appcode, string userID) {
this.GetQuestionTaskListAsync(appcode, userID, null);
}

/// <remarks/>
public void GetQuestionTaskListAsync(string appcode, string userID, object userState) {
if ((this.GetQuestionTaskListOperationCompleted == null)) {
this.GetQuestionTaskListOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetQuestionTaskListOperationCompleted);
}
this.InvokeAsync("GetQuestionTaskList", new object[] {
appcode,
userID}, this.GetQuestionTaskListOperationCompleted, userState);
}

private void OnGetQuestionTaskListOperationCompleted(object arg) {
if ((this.GetQuestionTaskListCompleted != null)) {
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.GetQuestionTaskListCompleted(this, new GetQuestionTaskListCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
}
}

/// <remarks/>
public new void CancelAsync(object userState) {
base.CancelAsync(userState);
}
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
public delegate void GetRecordNumCompletedEventHandler(object sender, GetRecordNumCompletedEventArgs e);

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class GetRecordNumCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {

private object[] results;

internal GetRecordNumCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}

/// <remarks/>
public int[] Result {
get {
this.RaiseExceptionIfNecessary();
return ((int[])(this.results[0]));
}
}
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
public delegate void GetVoteListCompletedEventHandler(object sender, GetVoteListCompletedEventArgs e);

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class GetVoteListCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {

private object[] results;

internal GetVoteListCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}

/// <remarks/>
public System.Data.DataSet Result {
get {
this.RaiseExceptionIfNecessary();
return ((System.Data.DataSet)(this.results[0]));
}
}
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
public delegate void VoteCompletedEventHandler(object sender, VoteCompletedEventArgs e);

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class VoteCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {

private object[] results;

internal VoteCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}

/// <remarks/>
public bool Result {
get {
this.RaiseExceptionIfNecessary();
return ((bool)(this.results[0]));
}
}
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
public delegate void GiveUpCompletedEventHandler(object sender, GiveUpCompletedEventArgs e);

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class GiveUpCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {

private object[] results;

internal GiveUpCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}

/// <remarks/>
public bool Result {
get {
this.RaiseExceptionIfNecessary();
return ((bool)(this.results[0]));
}
}
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
public delegate void GetQuestionTaskListCompletedEventHandler(object sender, GetQuestionTaskListCompletedEventArgs e);

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class GetQuestionTaskListCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {

private object[] results;

internal GetQuestionTaskListCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}

/// <remarks/>
public System.Data.DataSet Result {
get {
this.RaiseExceptionIfNecessary();
return ((System.Data.DataSet)(this.results[0]));
}
}
}
}

方法三:利用http 協(xié)議的get和post
這是最為靈活的方法。
復(fù)制代碼 代碼如下:www.zhaotila.cn

View Code
using System;
using System.Collections;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace Bingosoft.RIA.Common
{
/// <summary>
/// 利用WebRequest/WebResponse進(jìn)行WebService調(diào)用的類
/// </summary>
public class WebServiceCaller
{
#region Tip:使用說(shuō)明
//webServices 應(yīng)該支持Get和Post調(diào)用,在web.config應(yīng)該增加以下代碼
//<webServices>
// <protocols>
// <add name="HttpGet"/>
// <add name="HttpPost"/>
// </protocols>
//</webServices>
//調(diào)用示例:
//Hashtable ht = new Hashtable(); //Hashtable 為webservice所需要的參數(shù)集
//ht.Add("str", "test");
//ht.Add("b", "true");
//XmlDocument xx = WebSvcCaller.QuerySoapWebService("http://localhost:81/service.asmx", "HelloWorld", ht);
//MessageBox.Show(xx.OuterXml);
#endregion
/// <summary>
/// 需要WebService支持Post調(diào)用
/// </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調(diào)用
/// </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調(diào)用(Soap),參數(shù)Pars為String類型的參數(shù)名、參數(shù)值
/// </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("http://soap:Body/*/*", mgr).InnerXml;
doc2.LoadXml("<root>" + RetXml + "</root>");
AddDelaration(doc2);
return doc2;
}
private static string GetNamespace(String URL)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL + "?WSDL");
SetWebRequest(request);
WebResponse response = request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
XmlDocument doc = new XmlDocument();
doc.LoadXml(sr.ReadToEnd());
sr.Close();
return doc.SelectSingleNode("http://@targetNamespace").Value;
}
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_x_x("soap", "Body", "http://schemas.xmlsoap.org/soap/envelope/");
XmlElement soapBody = doc.CreateElement("soap", "Body", "http://schemas.xmlsoap.org/soap/envelope/");
//XmlElement soapMethod = doc.createElement_x_x(MethodName);
XmlElement soapMethod = doc.CreateElement(MethodName);
soapMethod.SetAttribute("xmlns", XmlNs);
foreach (string k in Pars.Keys)
{
//XmlElement soapPar = doc.createElement_x_x(k);
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();
}
}
/// <summary>
/// 設(shè)置憑證與超時(shí)時(shí)間
/// </summary>
/// <param name="request"></param>
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);
}
private static Hashtable _xmlNamespaces = new Hashtable();//緩存xmlNamespace,避免重復(fù)調(diào)用GetNamespace
}
}

分享:ASP.NET利用MD.DLL轉(zhuǎn)EXCEL具體實(shí)現(xiàn)
首先引入MD.dll 文件(附有下載地址)然后建立無(wú)CS文件的DownExcel.aspx 文件,接下來(lái)是調(diào)用方法,感興趣的朋友可以參考下哈

來(lái)源:模板無(wú)憂//所屬分類:.Net教程/更新時(shí)間:2013-05-22
相關(guān).Net教程
欧美激情精品久久久久| 日本高清无吗v一区| а天堂中文在线资源| 成人av色在线观看| 一区二区免费视频| x88av在线| 高清一区二区三区日本久| 91首页免费视频| 成人18视频免费69| 久久久久久免费看| 亚洲男女一区二区三区| 一级黄色免费毛片| 日韩一区二区三区高清免费看看| 一本色道久久综合精品婷婷| 动漫一区二区在线| 色拍拍在线精品视频8848| 丰满岳乱妇国产精品一区| 热99这里只有精品| 五月天网站亚洲| 日韩欧美性视频| 丰满女人性猛交| 欧美精品久久99| 在线免费观看av网址| 久久资源av| 亚洲精品乱码久久久久久金桔影视 | 国产成人亚洲综合色影视| 伊人婷婷久久| 欧美大片在线观看| 亚洲av无码国产精品永久一区| 97成人在线免费视频| 日韩国产精品一区| 国产校园另类小说区| 国产一级一片免费播放放a| 亚洲午夜高清视频| 精品国产91久久久| 欧美一级做a爰片免费视频| 欧美日韩激情视频在线观看| 97视频在线观看成人| 国产精品国产三级国产aⅴ入口 | 日本美女视频网站| 国产成+人+综合+亚洲欧美丁香花| 亚洲免费电影在线| www.久久久久久久| 亚洲免费看av| 日韩免费精品视频| 一起草av在线| 日韩精品电影一区亚洲| 97超碰国产精品| 国内免费久久久久久久久久久| 五月天婷婷综合| 国产高清不卡一区二区| 波多野结衣黄色网址| 亚洲成人精品在线播放| 中文字幕欧美日韩一区二区| 国产激情久久久| 日韩一区二区在线看| 99久久精品免费看| 国产黄色一级大片| 欧美色图亚洲激情| 正义之心1992免费观看全集完整版| www.久久色.com| 亚洲欧美日韩在线不卡| 老牛影视av牛牛影视av| 91国偷自产中文字幕久久| 国产成人精品一区二三区| 九九精品在线观看视频| 国产高清中文字幕| 国产成人亚洲欧洲在线| 国产成人av一区二区三区不卡| 波多野结衣50连登视频| 一区二区精品免费视频| 欧美视频完全免费看| 亚洲一区二区人妻| 俄罗斯av网站| 久久艹中文字幕| 欧美亚洲国产bt| 久久久久久久久99精品| 日韩国产欧美三级| 国产精品亚洲欧美在线播放| 精品无码一区二区三区电影桃花| 日韩 中文字幕| 2022亚洲天堂| 日韩免费av一区| 欧洲在线免费视频| 久久国产精品一区二区三区| 中文av一区二区| 国产成人自拍视频在线| 色欲AV无码精品一区二区久久 | 国产麻豆视频一区| 波多野结衣一区二区在线| 无码人妻aⅴ一区二区三区69岛| 天天摸天天舔天天操| 日本新janpanese乱熟| 极品美女扒开粉嫩小泬| 欧美高清中文字幕| 超碰超碰超碰超碰超碰| 秋霞在线观看一区二区三区| 古典武侠综合av第一页| 成人精品久久久| 久久久综合av| 欧美国产极速在线| 亚洲第一页中文字幕| 欧美一卡二卡在线| 色999日韩国产欧美一区二区| 久久久www免费人成精品| 国产成人一区在线| 99国产在线播放| 国产精品久久777777换脸| 女同久久另类69精品国产| 极品少妇一区二区三区精品视频| 欧美精品一区二区在线播放| 黄色片子免费看| 亚洲视频一二区| 91精品在线观| 中文字幕av免费在线观看| 亚洲一区二区欧美激情| 国模视频一区二区| 91看片淫黄大片91| 我和岳m愉情xxxⅹ视频| 丰满人妻一区二区三区无码av| 一本大道久久a久久精二百| 美日韩精品免费视频| 国产一区二区三区网站| 韩日欧美一区二区| 日韩毛片在线免费观看| 国产拍欧美日韩视频二区| 57pao精品| av网站在线不卡| 黑人巨大精品欧美| 成+人+亚洲+综合天堂| 久久久久久久亚洲精品| 国产二级一片内射视频播放| |精品福利一区二区三区| 91精品综合久久久久久五月天| 久热在线视频观看| 国产成人免费看一级大黄| 国产精品三级av| 欧美日本中文字幕| 久久9精品区-无套内射无码| 最新在线中文字幕| 可以免费看不卡的av网站| 欧美激情中文字幕| 欧美不卡在线视频| 国产91在线播放| 日本中文字幕精品| 精品午夜久久福利影院| 国产一区二区三区在线| 一区二区不卡在线观看| 亚洲av人无码激艳猛片服务器| 色婷婷激情综合| 亚洲图色中文字幕| 精品成人av一区二区在线播放| 一区二区三区资源| 女人天堂av手机在线| 国产精品一区二区黑丝| 亚洲最大在线视频| 日本在线观看a| 香蕉久久国产av一区二区| 精品伦理精品一区| 国产人妻777人伦精品hd| 国产一区二区三区三州| 99热在这里有精品免费| 亚洲成色www8888| av资源站久久亚洲| 高清中文字幕mv的电影| 中文字幕乱码在线观看| 日韩精品一区二区三区四区视频| 欧美大香线蕉线伊人久久国产精品| 日韩成人av毛片| 精品国产一区二区三区av性色| 强伦人妻一区二区三区| 日韩欧美国产精品一区| 日本视频在线免费| 欧美精品视频www在线观看| 中文精品视频一区二区在线观看| 全程偷拍露脸中年夫妇| 亚洲美女免费在线| 色综合电影网| 天天夜碰日日摸日日澡性色av| 精品无码在线视频| 性中国古装videossex| 亚洲福利电影网| 97在线视频观看| a级片在线观看| 国产欧美日韩三区| 亚洲欧美在线x视频| 91精品久久久久久久久久| 无码人妻精品一区二区蜜桃色欲| 日韩午夜三级在线| 日批视频免费看| 久久久久久久久久久黄色| 蜜桃视频日韩| 国产精品一区免费在线观看| r级无码视频在线观看| 欧美一卡二卡在线观看| 久久中文字幕免费| 亚洲一区二区三区sesese| 青青草国产精品亚洲专区无| 精品免费日产一区一区三区免费| 精品人妻午夜一区二区三区四区 | 亚洲aⅴ乱码精品成人区| 中文字字幕码一二三区| 国产福利一区二区三区视频| 久久精品视频99| 国产精品久久久久久9999| 欧美日韩一区二区免费视频| 国产欧美日韩小视频| 青草av.久久免费一区| 国产精品一区二区久久精品| 免费精品一区二区| 综合国产在线观看| 欧美激情一区二区视频| 亚洲国产精品成人va在线观看| 国产女女做受ⅹxx高潮| 国产婷婷色一区二区三区| 国产精品一区二区你懂得| 免费观看毛片网站| 色狠狠av一区二区三区香蕉蜜桃| 蜜臀av色欲a片无码精品一区 | 99爱视频在线| 日日夜夜精品视频免费| 亚洲深夜福利视频| 国产亚洲视频一区| 2014亚洲片线观看视频免费| 91九色丨porny丨国产jk| 国产精品国产三级国产专播品爱网 | 精品日韩一区二区三区| 免费无码毛片一区二区app| 美女视频久久| 欧美色倩网站大全免费| 国产成人在线播放视频| 91久久久在线| 亚洲午夜激情av| 国产精品视频在| 日韩一区二区av| 波多野结衣黄色网址| 欧美大黄免费观看| 国产精品成人aaaa在线| 欧美成人性色生活仑片| 亚洲综合精品在线| 国产999精品久久久| 久青草免费视频| 欧美激情成人在线视频| 你懂的网站在线| 久久精品午夜福利| 精品亚洲精品福利线在观看| 久章草在线视频| 欧美在线免费视屏| 美女又爽又黄视频毛茸茸| 91精品国产欧美日韩| 亚洲综合第一区| 亚洲精品国产电影| 日韩精品视频一区二区在线观看| 国产无遮挡aaa片爽爽| 不卡的av电影| a级大片在线观看| 91国产在线播放| 91精品在线观看入口| 超碰免费在线97| 国产精品久久久久9999| 国产无遮挡又黄又爽又色视频| 久久久欧美一区二区| 日本视频www色| 亚洲视频在线观看网站| 性生活一级大片| 亚洲高清不卡在线观看| 日日夜夜精品视频免费观看| 秋霞成人午夜鲁丝一区二区三区| 久久综合一区二区| 国产三级av在线播放| 亚洲欧洲第一视频| 亚洲精品国产片| 麻豆精品视频| 五月综合激情日本mⅴ| 中文字幕第69页| 国产成人涩涩涩视频在线观看 | 91精品国产成人www| 亚洲人妻一区二区三区| 深夜黄色小视频| 国产噜噜噜噜久久久久久久久| 天天影视色香欲综合网老头| 欧美一级大片免费看| 色综合五月天导航| 丁香激情综合五月| 美女又爽又黄视频毛茸茸| 午夜精品免费在线观看| 国产高清视频免费在线观看| 国产精品色午夜在线观看| 国产蜜臀97一区二区三区| 成人a v视频| 欧美激情乱人伦一区| 蜜臀av一区二区在线免费观看 | 亚洲精品国产无码| 国产又粗又硬又长| 亚洲天堂av在线免费| 超碰在线播放97| 欧美亚洲精品一区二区| 在线亚洲男人天堂| 日一区二区三区| 色www免费视频| 欧美一区二区美女| 无码人妻一区二区三区线| 视频一区视频二区视频| 欧美高清hd18日本| 日韩综合小视频| 91网站免费视频| 国产成人久久久| 中文字幕在线播放不卡一区| 黑人一级大毛片| 日韩国产欧美亚洲| 欧美精品一区二区久久久| 中文字幕av久久爽av| 亚洲精品久久久久久一区二区| www.精品av.com| 国产成人精品午夜视频免费| 国产福利久久久| 日韩aaaaa| 免费看黄在线看| av一区二区三区免费| 久久久久久九九九| 制服丝袜av成人在线看| 亚洲日本欧美天堂| 成人黄色免费网| 欧美 日本 亚洲| 俺去亚洲欧洲欧美日韩| 成人av中文字幕| 中文字幕一区二区人妻视频| 欧美成人xxxxx| 久久久精品久久久久| 亚洲日本青草视频在线怡红院| 久久久久久久极品内射| 欧美日韩激情在线| 日韩欧美中文视频| 国产精品久久久久久久av电影| 精品乱码亚洲一区二区不卡| 亚洲视频免费在线观看| 欧美一区二不卡视频| 99视频在线免费| 国产精品成久久久久三级| 精品1区2区在线观看| 亚洲美女淫视频| 日韩视频在线观看免费视频| 国产日韩精品推荐| 精品噜噜噜噜久久久久久久久试看| 成人免费毛片嘿嘿连载视频| 欧美精品一级片| 水蜜桃av无码| 午夜性福利视频| 国产精品一区二区小说| 亚洲精品一品区二品区三品区| 亚洲sss综合天堂久久| 国产91在线高潮白浆在线观看 | 亚洲欧洲视频在线| av一区二区三区| 国产精品自拍99| 五月天丁香花婷婷| 久久精品国产精品国产精品污| 在线观看久久久久久| 狠狠躁夜夜躁人人爽超碰91| 精品一区二区三区在线视频| 成人性生交大免费看| 四虎永久在线精品免费一区二区| 综合久久五月天| 亚洲国产精品久久久久秋霞蜜臀 | 国产成人一区二| 欧美在线视频免费观看| 国产精品国产自产拍高清av水多 | av免费一区二区| 中文字幕中文字幕在线中心一区| 久久在线精品视频| 色综合久久久久网| gogogo免费视频观看亚洲一| 亚洲天堂一二三| 疯狂撞击丝袜人妻| 自拍一级黄色片| 婷婷视频在线播放| 国产激情999| 一个人看的www久久| 欧美电影免费观看完整版| 亚洲欧美日韩久久精品| 成人avav影音| 性一交一乱一色一视频麻豆| 制服丝袜中文字幕第一页| 亚洲国产高清国产精品| 欧美日本精品在线| 337p亚洲精品色噜噜噜| 国产精品入口麻豆原神| 手机在线观看毛片| 唐朝av高清盛宴| 91人妻一区二区三区| 奇米视频888战线精品播放| 欧美乱妇高清无乱码| 色噜噜狠狠成人网p站| www..com久久爱| 久久中文在线| 波多野结衣爱爱| 人妻一区二区视频| 黄色网页免费在线观看| 91在线观看免费高清| 精品国偷自产在线| 亚洲欧美日韩一区二区三区在线| 91精品国产麻豆| 欧美三级韩国三级日本三斤| 日本一区二区三区四区在线视频| 爽好久久久欧美精品| 涩涩视频在线观看| 精品人妻一区二区三区潮喷在线| www.com国产| 加勒比在线一区| 日韩av在线播放观看|