405不允许的方法错误WCF [英] 405 Method Not Allowed Error in WCF

查看:104
本文介绍了405不允许的方法错误WCF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能发现这个实现的问题?我可以在浏览器中打开它和它的作品,但是从客户端的调用(同时使用jQuery和asp.net阿贾克斯失败)

Can someone spot the problem with this implementation? I can open it up in the browser and it works, but a call from client side (using both jquery and asp.net ajax fails)

服务合同

[OperationContract(Name = "GetTestString")]
[WebInvoke(Method = "GET",
           ResponseFormat = WebMessageFormat.Json
   )]
string GetTestString();

在其他绑定中Web.config中,我有一个webHttp结合

In Web.config among other bindings, I have a webHttp binding

<endpoint address="ajax" binding="webHttpBinding" contract="TestService" behaviorConfiguration="AjaxBehavior" />

终结点行为

  <endpointBehaviors>
    <behavior name="AjaxBehavior">
      <enableWebScript/>
    </behavior>
  </endpointBehaviors>
</behaviors>

SVC文件

<%@ ServiceHost Service="TestService" %>

客户端

var serviceUrl = "http://127.0.0.1/Test.svc/ajax/";
var proxy = new ServiceProxy(serviceUrl);

我然后使用该方法在 HTTP://www.west-wind .COM /博客/职位/ 324917.aspx
调用服务

推荐答案

你的链接上的示例使用HTTP POST,而不是一个程序的HTTP GET。这就是法[即]的不允许的。 - 您需要更改code做一个GET代替

The example on your link uses a Http POST, not a Http GET. That's the "method [that's] not allowed" - you need to change the code to do a GET instead.

您发布的是你的客户端code源链接有此块:

The link you post that was your source for client code has this block:

 $.ajax( { 
                url: url,
                data: json,
                type: "POST",
                processData: false,
                contentType: "application/json",
                timeout: 10000,
                dataType: "text",  // not "json" we'll parse

请注意在键入:POST在那里 - 你将需要GET。我假设你已经从你发布的链接采取的JQuery的,因为405的状态表明,你的呼叫的code是错误的,而不是服务。

Note the type: "POST" in there - yours would need to be "GET". I'm assuming you've taken your JQuery from the link you posted, because the 405 status suggests that your calling code is wrong, not the service.

这篇关于405不允许的方法错误WCF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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