Wcf Azure 405方法不允许出现错误。。。
正在寻找有关此错误的帮助 我有一个从Javascript调用的Azure WCF服务。但是,当我从JavaScript调用我的WCF服务时,出现以下错误: -405方法不允许 在WCF服务界面上,如下所示:Wcf Azure 405方法不允许出现错误。。。,wcf,azure,Wcf,Azure,正在寻找有关此错误的帮助 我有一个从Javascript调用的Azure WCF服务。但是,当我从JavaScript调用我的WCF服务时,出现以下错误: -405方法不允许 在WCF服务界面上,如下所示: [ServiceContract] public interface ICSServiceLevel { [OperationContract] [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle
[ServiceContract]
public interface ICSServiceLevel
{
[OperationContract]
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "getservicelevel")]
List<ServiceLevel> GetServiceLevel(long id);
}
接口的实现:
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class CSServiceLevel : ICSServiceLevel
{
public List<ServiceLevel> GetServiceLevel(long id)
{
List<ServiceLevel> retValue;
//...
return (retValue);
}
}
服务角色的Web.config为:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service behaviorConfiguration="CloudWCFServiceBehavior" name="CSServiceLevel">
<endpoint address="" binding="webHttpBinding" behaviorConfiguration="JsonEndpointBehavior"
contract="Services.ICSServiceLevel" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CloudWCFServiceBehavior">
<useRequestHeadersForMetadataAddress>
<defaultPorts>
<add scheme="http" port="81"/>
<add scheme="https" port="444"/>
</defaultPorts>
</useRequestHeadersForMetadataAddress>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="JsonEndpointBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
And finally the way I call it is :
var data = '{ "id" : -1}';
$.ajax({
data: data, cache: false, success: populateCustomerGrid,
type: "POST", dataType: "json", contentType: "application/json",
url: "http://mydomain.cloudapp.net:81/CSServiceLevel.svc/getservicelevel"
});
有人知道问题出在哪里吗?此外,在服务的webrole定义中,我确实将端点设为81为什么使用POST动词而不是GET动词?您的方法名称暗示它是只读幂等资源。是否在.csdef文件中为端口81和444设置了绑定
你可能还想联系Fiddler,确保你发送的是正确的东西。通常在JQuery中,您会将数据作为对象传递,而不是预序列化的JSON字符串,因此这可能也会导致问题 将其更改为获取接口定义和调用。但仍然会得到相同的错误。