2014-10-07 165 views
0

我已經創建了一個Web服務,以節省錯誤日誌如何使用WEB服務?

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Runtime.Serialization; 
using System.ServiceModel; 
using System.ServiceModel.Web; 
using System.Text; 
using Microsoft.Practices.EnterpriseLibrary.Data.Sql; 
using System.Configuration; 
using System.Data.Common; 
using System.Data; 
using System.Net.Mail; 

using System.IO; 

namespace TestErrorHandling 
{ 
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together. 
    public class Service1 : IService1 
    { 
     public int SaveErrorLog(CompositeType objCom) 
     { 
      int messageId = 0; 

      try 
      { 
       SqlDatabase _errDBConnection = null; 
       _errDBConnection = new SqlDatabase(ConfigurationManager.ConnectionStrings["ErrorLogConnStr"].ToString()); 

       DbCommand dbCommand = _errDBConnection.GetStoredProcCommand("usp_SaveErrorLog"); 
       _errDBConnection.AddInParameter(dbCommand, "@i_ApplicationId", DbType.Int32, objCom.AppId); 
       _errDBConnection.AddInParameter(dbCommand, "@i_ExceptionType", DbType.String, objCom.ExceptionType); 
       _errDBConnection.AddOutParameter(dbCommand, "@O_MESSAGEID", DbType.Int32, 4); 
       _errDBConnection.ExecuteReader(dbCommand); 
       messageId = Convert.ToInt32(_errDBConnection.GetParameterValue(dbCommand, "@O_MESSAGEID")); 
      } 
      catch (Exception ex) 
      { 
        throw new FaultException(ex.Message); 
      } 
      return messageId; 
     } 


    } 
} 

現在我在我的web應用程序

using System.Collections; 
using System.Collections.Generic; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Web.UI.HtmlControls; 
using System.Xml; 
using System.Collections.Specialized; 
using Test.ServiceReference1; 

namespace Test 
{ 
    public partial class _Default : BasePage 
    { 
      ServiceReference1.Service1Client obj1 = new ServiceReference1.Service1Client; 

       obj1. 

} 

但輸入OBJ1後調用這個服務。它沒有顯示服務的SaveErrorLog方法。 請幫我解決這個問題。

加入像enter image description here

+0

你是如何在Web應用程序中添加Web服務引用? – DevelopmentIsMyPassion 2014-10-07 09:42:41

+0

我已經添加了引用,通過添加Web引用 – Vandana 2014-10-07 12:19:03

+0

在'[OperationContract]'裝飾'IService1'界面中的'SaveErrorLog'方法? – Szeki 2015-04-10 07:23:27

回答

1

變化

ServiceReference1.Service1Client obj1 = new ServiceReference1.Service1Client; 

ServiceReference1.Service1Client obj1 = new ServiceReference1.Service1Client(); 

,然後使用

obj1.<method name> 

也使用添加服務參照的文添加參考CES

這樣的.. enter image description here

enter image description here

enter image description here

enter image description here

+0

是的,我使用了ServiceReference1.Service1Client obj1 = new ServiceReference1.Service1Client();仍然obj1。方法名稱不來 – Vandana 2014-10-07 12:17:45

+0

嘗試添加服務引用,而不是Web引用 – 2014-10-07 12:37:27

+0

是添加了服務引用添加圖像... – Vandana 2014-10-07 12:43:48