Bu sorunun birçok kez yayınlandığını biliyorum, ancak neredeyse hepsini (internetteki derslerin çoğunu) okudum ve Hala yanlış yaptığımı anlayamıyorum.jQuery'den bir ASP.NET 4.0 WCF hizmetinin çağrılması 400 Hatalı İstek veriliyor
Bir jQuery betiği tarafından tüketilmek üzere bir WCF web hizmeti geliştirdiğimiz bir web sitesinde uygulamayı denedim, ancak AJAX isteğini gerçekleştirirken 400 Bad Request
almaya devam ediyorum ve umudumu kaybetmeye başlıyorum.
Lütfen WCF'ye yeni olduğumu ve sadece çevrimiçi eğiticilerle oluşturduğumu unutmayın, bu yüzden bir şeyi gözden kaçırdığım veya büyük ölçüde hapsettiğim tamamen mümkün.
Sorular Denedim ama yardım etmedi:
- WCF Service returns 400 Bad Request
- uploading large xml to WCF REST service -> 400 Bad request
- 400 Bad Request HTTP Response using a WCF POST via JQuery
- Error 400 (Bad Request) with WCF Tutorial?
- Why does my C# client, POSTing to my WCF REST service, return (400) Bad Request?
Dış r esources Ben boşuna okuyun:
- http://www.west-wind.com/weblog/posts/324917.aspx
- http://www.c-sharpcorner.com/UploadFile/sridhar_subra/116/
- http://learningbyfailing.com/2008/05/calling-wcf-from-jquery-using-parameters/
- http://iainjmitchell.com/blog/?p=97
- diğer birçok ... Ben de yeni bir çözüm oluşturma çalıştı
, sadece bir sayfa ve servis ile müdahaleler, ama yine de aynı sorun var.
IService.cs
namespace WebService
{
using System;
using System.ServiceModel;
using System.ServiceModel.Web;
[ServiceContract(Name = "Service", Namespace = "WebService")]
public interface IService
{
[OperationContract]
[WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
String Test();
}
}
Service.svc.cs
namespace WebService
{
using System;
public class Service : IService
{
public String Test()
{
return "Hello, world.";
}
}
}
default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebService.Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#doAjax").click(function (event) {
event.preventDefault();
jQuery.ajax({
contentType: "application/json"
, dataType: "text"
, error: function (jqXHR, textStatus, errorThrown) {
console.group("AJAX error:");
console.debug(jqXHR);
console.debug(textStatus);
console.groupEnd();
}
, processData: false
, success: function (data, textStatus, jqXHR) {
console.group("AJAX success:");
console.debug(data);
console.debug(textStatus);
console.debug(jqXHR);
console.groupEnd();
}
, type: "post"
, url: "/Service.svc/Test"
});
});
});
</script>
<title>WebService</title>
</head>
<body>
<form runat="server">
<h1><%= this.Page.Title %></h1>
<p><input id="doAjax" type="button" value="Run" /></p>
</form>
</body>
</html>
: Burada kod bulabilirsiniz
Web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings />
<client />
<behaviors>
<endpointBehaviors>
<behavior name="Behavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="Service">
<endpoint behaviorConfiguration="Behavior" binding="webHttpBinding" contract="WebService.IService" />
</service>
</services>
</system.serviceModel>
</configuration>
Bu soruya bir cevap buldunuz mu? Ben aynı sorunu yaşıyorum ve çözüm bulamadık ... :( –
@NaveedButt Hayır, ve diğer projelere taşındı beri. Aşağıdaki cevapları deneyin, ve eğer yapabiliyorsanız, bir cevap/yorum – Albireo
Sayfanın başına bir div koyarak ve html'yi hata durumunda jqXHR'ye ayarlayarak hata hakkında daha fazla ayrıntı görebiliyorum. Bu şekilde daha iyi bir çıktı sunacağım. Burada bir çözüm bulacağım, burada bir hata buldum. –