在使用DataService类中的[WebInvoke]用法调用服务操作时,方法不允许异常 [英] 405 Method not Allowed exception when calling Service Operation with [WebInvoke] usage in DataService class

查看:91
本文介绍了在使用DataService类中的[WebInvoke]用法调用服务操作时,方法不允许异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我有一个服务操作方法,用于将数据插入我的实体,然后保存到数据库。但是,当我调用服务操作时(http://localhost/SupplierSvc.svc/AddToTbl,它返回一个例外Http 405方法不允许。)
       ;  [WebInvoke]
       公共无效AddToTbl()
        {
            i_Supplier供应商=新i_Supplier()
       &NBSP ;    {
               供应商ID = QUOT;试验" ;,
               供应商名称="名称            };

            CurrentDataSource。 AddObject("i_Supplier",供应商);
   ;          CurrentDataSource.SaveChanges();
       抛出的异常是DataServiceException。下面是堆栈跟踪:

BODY {font:x-small'Verdana'; margin-right:1.5em} .c {cursor:hand} .b {color:red; font-family: 'Courier New'; font-weight:bold; text-decoration:none} .e {margin-left:1em; text-indent:-1em; margin-right:1em} .k {margin-left:1em; text-缩进:-1em; margin-right:1em} .t {color:#990000} .xt {color:#990099} .ns {color:red} .dt {color:green} .m {color:blue} .tx {font-weight:bold} .db {text-indent:0px; margin-left:1em; margin-top:0px; margin-bottom:0px; padding-left:.3em; border-left:1px solid #CCCCCC; font:small Courier} .di {font:small Courier} .d {color:blue} .pi {color:blue} .cb {text-indent:0px; margin-left:1em; margin-top:0px; margin-底部:0像素;填充左:.3em;字体:小信使;颜色:#888888} {.CI字体:小信使;颜色:#888888} {PRE余量:0像素;显示:内联}
将脚本><! -
函数f(e){
if(e.className ==" ci"){if(e.children(0).innerText.indexOf(" \\ \\ n")> 0)修复(e,"cb");}
if(e.className ==" di"){if(ec) hildren(0).innerText.indexOf(" \ n")> 0)fix(e,"db");}
e.id ="" ;;
}
函数修复(e,cl){
e.className = cl;
e.style.display =" block" ;;
j = e.parentElement.children(0);
j.className =" c" ;;
k = j.children(0);
k.style.visibility =" visible" ;;
k.href ="#" ;;
}
函数ch(e){
mark = e.children(0).children(0);
if(mark.innerText ==" +"){
mark.innerText =" - " ;;
for(var i = 1; i< e.children.length; i ++)
e.children(i).style.display =" block" ;;
}
else if(mark.innerText ==" - "){
mark.innerText =" +" ;;
for(var i = 1; i< e.children.length; i ++)
e.children(i).style.display =" none" ;;
}}
函数ch2(e){
mark = e.children(0).children(0);
contents = e.children(1);
if(mark.innerText ==" +"){
mark.innerText =" - " ;;
if(contents.className ==" db" || contents.className ==" cb")
contents.style.display =" block" ;;
else contents.style.display =" inline" ;;
}
else if(mark.innerText ==" - "){
mark.innerText =" +" ;;
contents.style.display =" none" ;;
}}
函数cl(){
e = window.event.srcElement;
if(e.className!=" c"){e = e.parentElement; if(e.className!=" c"){return;}}
e = e.parentElement;
if(e.className ==" e")ch(e);
if(e.className ==" k")ch2(e);
}
函数ex(){}
函数h(){window.status =" " ;;}
document.onclick = cl;
- >< / script>

Basically I have a service operation method for inserting data to my entity and then saved to the database. However when I called the service operation (http://localhost/SupplierSvc.svc/AddToTbl, it returns me an exception Http 405 Method not allowed.

        [WebInvoke]
        public void AddToTbl()
        {
            i_Supplier supplier = new i_Supplier()
            {
                Supplier ID = "Test",
                Supplier Name = "Name
            };

            CurrentDataSource.AddObject("i_Supplier", supplier);
            CurrentDataSource.SaveChanges();
        }

The exception that is thrown is a DataServiceException. Below is the stack trace:

BODY{font:x-small 'Verdana';margin-right:1.5em} .c{cursor:hand} .b{color:red;font-family:'Courier New';font-weight:bold;text-decoration:none} .e{margin-left:1em;text-indent:-1em;margin-right:1em} .k{margin-left:1em;text-indent:-1em;margin-right:1em} .t{color:#990000} .xt{color:#990099} .ns{color:red} .dt{color:green} .m{color:blue} .tx{font-weight:bold} .db{text-indent:0px;margin-left:1em;margin-top:0px;margin-bottom:0px;padding-left:.3em;border-left:1px solid #CCCCCC;font:small Courier} .di{font:small Courier} .d{color:blue} .pi{color:blue} .cb{text-indent:0px;margin-left:1em;margin-top:0px;margin-bottom:0px;padding-left:.3em;font:small Courier;color:#888888} .ci{font:small Courier;color:#888888} PRE{margin:0px;display:inline} <script><!-- function f(e){ if (e.className=="ci"){if (e.children(0).innerText.indexOf("\n")>0) fix(e,"cb");} if (e.className=="di"){if (e.children(0).innerText.indexOf("\n")>0) fix(e,"db");} e.id=""; } function fix(e,cl){ e.className=cl; e.style.display="block"; j=e.parentElement.children(0); j.className="c"; k=j.children(0); k.style.visibility="visible"; k.href="#"; } function ch(e){ mark=e.children(0).children(0); if (mark.innerText=="+"){ mark.innerText="-"; for (var i=1;i<e.children.length;i++) e.children(i).style.display="block"; } else if (mark.innerText=="-"){ mark.innerText="+"; for (var i=1;i<e.children.length;i++) e.children(i).style.display="none"; }} function ch2(e){ mark=e.children(0).children(0); contents=e.children(1); if (mark.innerText=="+"){ mark.innerText="-"; if (contents.className=="db"||contents.className=="cb") contents.style.display="block"; else contents.style.display="inline"; } else if (mark.innerText=="-"){ mark.innerText="+"; contents.style.display="none"; }} function cl(){ e=window.event.srcElement; if (e.className!="c"){e=e.parentElement;if (e.className!="c"){return;}} e=e.parentElement; if (e.className=="e") ch(e); if (e.className=="k") ch2(e); } function ex(){} function h(){window.status=" ";} document.onclick=cl; --></script>

<? xml version =" 1.0"编码= QUOT; UTF-8英寸独立= QUOT;是" ?>

推荐答案



您如何调用服务操作?我们的.NET客户端目前不支持本地服务操作,因此我假设您正在使用一些自定义代码来执行此操作。为此,该代码需要确保请求将具有HTTP谓词POST,而不是GET。

谢谢,
Hi,

How are you calling the service operation? Our .NET client doesn't currently support service operations natively, so I'm assuming you're using some custom code to do that. For this to work, that code needs to make sure, that the request will have the HTTP verb POST, not GET.

Thanks,


这篇关于在使用DataService类中的[WebInvoke]用法调用服务操作时,方法不允许异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆