日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Web Service应用举例 及一问题的解决方法

發布時間:2023/12/13 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Web Service应用举例 及一问题的解决方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

由于系統要求?需要做一webservice將應用服務器的壓力分配到其它的機器上,于是寫了下面的WebSerivce服務
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using DBCore;

namespace QQWebService
{
?/// <summary>
?/// QQMessage 的摘要說明。
?/// </summary>
?[WebService(Namespace="QQWebService")]
?public class QQMessage : System.Web.Services.WebService
?{
??DBCore.DataBaseVisitor.AbsDBHelper dbhelper = new DBCore.DataBaseVisitor.FactoryDBHelper().CreateDBHelper("DataBaseSql",DBCore.DataBaseVisitor.DataBaseConnectionType.Sql);

??public QQMessage()
??{
???//CODEGEN: 該調用是 ASP.NET Web 服務設計器所必需的
???InitializeComponent();
??}

??[WebMethod]
??public void SetDBHelperofSQLClient(string? conn)
??{
???this.dbhelper = new DBCore.DataBaseVisitor.JSLSqlHelper();
???dbhelper.SetDBConnection = conn;
??}

??[WebMethod]
??public DataSet GetSender(string userid)
??{
???string sql="select distinct Sender from tOA_Message_Temp_User where?? IsRead='0' and receiver='"+userid+"'";
???return dbhelper.ExecuteDataset(sql);
??}
...

???[WebMethod]
??public DataSet CSelectSys(ArrayList al)
??{
???if (al == null) return null;
???string sql = @"
???Select TopicID,Content,Sender,SendTime,IsSend,IsAutoBack,IsRead,Receiver,ReceiverTime,Sender as username
???From tOA_Message_Temp_User
???where Sender='$0$'
??????????? and Receiver='$1$'
???and IsRead='$2$'
??? ";
???for(int i = 0; i < al.Count; i++)
???{
????sql = sql.Replace("$"+i.ToString()+"$",al[i] != null ? al[i].ToString() : "");
???}
???return dbhelper.ExecuteDataset(sql.Replace("\t"," "));
??}

???#region 組件設計器生成的代碼
??
??//Web 服務設計器所必需的
??private IContainer components = null;
????
??/// <summary>
??/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
??/// 此方法的內容。
??/// </summary>
??private void InitializeComponent()
??{
??}

??/// <summary>
??/// 清理所有正在使用的資源。
??/// </summary>
??protected override void Dispose( bool disposing )
??{
???if(disposing && components != null)
???{
????components.Dispose();
???}
???base.Dispose(disposing);??
??}
??
??#endregion

??}
}

在系統當中添加web引用,關鍵位置做了如下處理
xxx.QQClient {
??? using System.Diagnostics;
??? using System.Xml.Serialization;
??? using System;
??? using System.Web.Services.Protocols;
??? using System.ComponentModel;
??? using System.Web.Services;
???
???
??? /// <remarks/>
??? [System.Diagnostics.DebuggerStepThroughAttribute()]
??? [System.ComponentModel.DesignerCategoryAttribute("code")]
??? [System.Web.Services.WebServiceBindingAttribute(Name="QQMessageSoap", Namespace="QQWebService")]
??? [System.Xml.Serialization.XmlIncludeAttribute(typeof(object[]))]
??? public class QQMessage : System.Web.Services.Protocols.SoapHttpClientProtocol {
???????
??????? /// <remarks/>
??????? public QQMessage() {
??????????? this.Url = "http://10.60.0.147/QQWebService/QQMessage.asmx";
??????? }
?
??public QQMessage(string url)
??{
???this.Url = url;
??}?????

??public QQMessage(string url, string conn)
??{
???this.Url = url;
???SetDBHelperofSQLClient(conn);
??}
...

在系統引用webservice時做如下類

using System;
using System.Collections;
using System.Data;
using DBCore;
namespace JQHY.jslqq
{
?/// <summary>
?/// JSLQQSource 的摘要說明。
?/// </summary>
?public class JSLQQSource
?{

??static JQHY.QQClient.QQMessage qc = new JQHY.QQClient.QQMessage(System.Configuration.ConfigurationSettings.AppSettings["QQClientSerivce"],System.Web.HttpContext.Current.Application["DataBaseSql"].ToString());

??static object[ ] ToArray( System.Collections.ICollection coll )
??{
???object[ ] result = new object[coll.Count];
???int i = 0;
???foreach( object obj in coll )
???{
????result[ i++ ] = obj;
???}
???return result;
??}
??public JSLQQSource()
??{

??}

??public DataSet GetSender(string userid)
??{
???return qc.GetSender(userid);
??}
??public DataSet CSelectSys(ArrayList al)
??{
???return qc.CSelectSys(ToArray(al));
??}
...

測試發現web service只能訪問本地資源,一直找不到問題所在 。
后來將程序部署到別的機器上試發現沒有此類問題,尋找很久,終于解決
得如下結論: :-)

復雜的問題往往有著簡單的答案
?[Web Service于Win2003下訪問SQLServer2000記得一定要打上SQLSever.SP3補丁]

轉載于:https://www.cnblogs.com/bigmouthz/archive/2006/04/19/379260.html

總結

以上是生活随笔為你收集整理的Web Service应用举例 及一问题的解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。