我收到错误 400,错误请求。
我有一组我试图写的页面。(仅列出相关)
- ./网页.aspx
- ./webservices/WebCalls.svc
- ./webservices/IWebCalls.cs
- ./Web.config
我一直在寻找让我的前端与 Webcalls 页面进行通信的方法,如下所示:
$.ajax({
url: "webservices/WebCalls.svc/DoWork",
success: function(){
console.log(arguments);
}
});
但它似乎不起作用。
我正在考虑这样创建文件:
WebCalls.svc:
public class WebCalls: IWebCalls
{
public string DoWork()
{
return "{\"hello\":\"Chop Wood, Carry Water.\"}";
}
}
和 IWebCalls.cs:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public interface IWebCalls
{
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "DoWork")]
string DoWork();
}
在我的 webConfig 中,我认为我设置正确:
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" httpGetUrl=""/>
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
<services>
<service behaviorConfiguration="ServiceBehavior" name="MyProj.WebCalls">
<endpoint address="" behaviorConfiguration="web" binding="webHttpBinding"
bindingConfiguration="LargeWeb" name="LargeWeb" contract="MyProj.webservices.IWebCalls" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="LargeWeb"
maxBufferPoolSize="15000000"
maxReceivedMessageSize="15000000"
maxBufferSize="15000000">
<readerQuotas
maxArrayLength="15000000"
maxBytesPerRead="15000000"
maxDepth="32"
maxNameTableCharCount="15000000"
maxStringContentLength="15000000"
/>
</binding>
</webHttpBinding>
</bindings>
当我运行它时,它只是告诉我它已经创建了一个服务,但是当我尝试调用:DoWork时,它会收到 400 错误。
我的方法有问题吗?我只是想建立一组页面,以便我可以查询数据。最初,我打算为我想要创建的每个函数创建一个 GenericHander.asxh,但我认为这空间太大。我知道这样的事情是一种选择,但似乎它不起作用。