我已經創建了一個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方法。 請幫我解決這個問題。
加入像
你是如何在Web應用程序中添加Web服務引用? – DevelopmentIsMyPassion 2014-10-07 09:42:41
我已經添加了引用,通過添加Web引用 – Vandana 2014-10-07 12:19:03
在'[OperationContract]'裝飾'IService1'界面中的'SaveErrorLog'方法? – Szeki 2015-04-10 07:23:27