服务端点错误 [英] service endpoint error
问题描述
我制作了一个网络服务,其中getleger功能如下所示:
public List< datalist7> getleger( string accno, string fromdate, string todate)
{
SqlConnection con = new SqlConnection( @ Data Source = saba-PC; Initial Catalog = bcounts; Integrated Security = True);
con.Open();
SqlCommand cmd = new SqlCommand( select gt.Value_Date,gt.Voucher_no +' - '+ gr.VchrType as goucher,gt.Acct_Nirration,gr.InstrumentNo,gt.Dr_Amount,gt.Cr_Amount from gl_transaction gt,gl_Ref gr其中gt.Accountno =' + accno + '和gt.Voucher_No = gr.Voucher_no和gt.Value_Date介于' + fromdate +之间 '和' + todate + ',con);
SqlDataReader rdr = cmd.ExecuteReader();
decimal crsum = 0 ;
decimal drsum = 0 ;
decimal balance = 0 ;
列表< datalist7> data = new List< datalist7>();
if (rdr.HasRows)
{
while (rdr .Read())
{
if (rdr.GetDecimal( 4 ) > 0 )
{
balance = balance + rdr.GetDecimal(< span class =code-digit> 4 );
drsum + = rdr.GetDecimal( 4 );
data.Add( new datalist7(rdr.GetDateTime( 0 )。ToShortDateString(), rdr.GetString( 1 ),rdr.GetString( 2 ),rdr.GetString( 3 ),rdr.GetDecimal( 4 )。ToString(), - ,balance.ToString()));
}
else
{
balance = balance - rdr.GetDecimal( 5 跨度>);
crsum + = rdr.GetDecimal( 5 );
data.Add( new datalist7(rdr.GetDateTime( 0 )。ToShortDateString(), rdr.GetString( 1 ),rdr.GetString( 2 ),rdr.GetString( 3 ), - ,rdr.GetDecimal(< span class =code-digit> 5 )。ToString(),balance.ToString()));
}
}
data.Add( new datalist7( - , - ,< span class =code-string> - , - ,drsum.ToString(),crsum.ToString(), - 跨度>));
}
con.Close();
返回数据;
}
和Service1.cs文件
[OperationContract]
[WebInvoke(Method =GET,ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate =getleger / accno = {accno}& fromdate = {fromdate}& todate = {todate})]
列表< datalist7 > getleger(string accno,string fromdate,string todate);
但每当我在这样的浏览器上调用此方法时
http:// localhost:49609 / ipadservice.svc / getleger / 0010010010006 / 2013-02-01 / 2014-02-01
显示:
未找到端点。请参阅服务帮助页面以构建对服务的有效请求。
是什么事?
< blockquote>你不遵守你的'UriTemplate'。此外,它是不正确的。
将其更改为:
UriTemplate =getleger ? accno = {accno }& fromdate = {fromdate}& todate = {todate}
我建议改变你的思维方式如果您使用restful服务,请访问对象。 getleger
类似于方法名称,但使用REST可以获得对象或更改对象的状态。
最好将uri模板设为:
UriTemplate =leger ? accno = {accno}& fromdate = {fromdate}& todate = {todate}
你打电话的
将是:
http:// localhost:49609 / ipadservice.svc / leger?accno = 123& fromdate = 20030101& todate = 20030102
并将其读作:
'给我带有accno = {accno}的legers和日期'fromdate'和'todate''
更多信息:
UriTemplate [ ^ ]
REST [ ^ ]
i had maked a webservice in which getleger function is maked like this :
public List<datalist7> getleger(string accno, string fromdate, string todate)
{
SqlConnection con = new SqlConnection(@"Data Source=saba-PC;Initial Catalog=bcounts;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("select gt.Value_Date,gt.Voucher_no+'-'+gr.VchrType as voucher,gt.Acct_Nirration,gr.InstrumentNo,gt.Dr_Amount,gt.Cr_Amount from gl_transaction gt, Gl_Ref gr where gt.Accountno = '" + accno + "' and gt.Voucher_No=gr.Voucher_no and gt.Value_Date between '" + fromdate + "' and '" + todate + "'", con);
SqlDataReader rdr = cmd.ExecuteReader();
decimal crsum = 0;
decimal drsum = 0;
decimal balance = 0;
List<datalist7> data = new List<datalist7>();
if (rdr.HasRows)
{
while (rdr.Read())
{
if (rdr.GetDecimal(4) > 0)
{
balance = balance + rdr.GetDecimal(4);
drsum += rdr.GetDecimal(4);
data.Add(new datalist7(rdr.GetDateTime(0).ToShortDateString(), rdr.GetString(1), rdr.GetString(2), rdr.GetString(3), rdr.GetDecimal(4).ToString(), "-", balance.ToString()));
}
else
{
balance = balance - rdr.GetDecimal(5);
crsum += rdr.GetDecimal(5);
data.Add(new datalist7(rdr.GetDateTime(0).ToShortDateString(), rdr.GetString(1), rdr.GetString(2), rdr.GetString(3), "-", rdr.GetDecimal(5).ToString(), balance.ToString()));
}
}
data.Add(new datalist7("-", "-", "-", "-", drsum.ToString(), crsum.ToString(), "-"));
}
con.Close();
return data;
}
and in Service1.cs file
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "getleger/accno={accno}&fromdate={fromdate}&todate={todate}")]
List<datalist7> getleger(string accno, string fromdate, string todate);
but whenever i called this method on browser like this
http://localhost:49609/ipadservice.svc/getleger/0010010010006/2013-02-01/2014-02-01
it shows :
Endpoint not found. Please see the service help page for constructing valid requests to the service.
what was the matter?
you are not comply with your 'UriTemplate'. moreover, it is ill-formed.
change it into:
UriTemplate = "getleger?accno={accno}&fromdate={fromdate}&todate={todate}"
and I advice to change your thinking-way from soa to objects if you use restful services.getleger
is like a method name but with 'REST' you get objects or change states of objects.
better to have uri template as:
UriTemplate = "leger?accno={accno}&fromdate={fromdate}&todate={todate}"
you call would be:
http://localhost:49609/ipadservice.svc/leger?accno=123&fromdate=20030101&todate=20030102
and read it as:
'give me legers having accno={accno} and between dates 'fromdate' and 'todate''
more info:
UriTemplate[^]
REST[^]
这篇关于服务端点错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!