Tôi đang sử dụng mã JQuery \ JavaScript sau đây để giao tiếp với một dịch vụ REST WCF 4.Cố gắng để có được một bài đăng JQuery để giao tiếp với WCF, nhưng dữ liệu JSON không được chấp nhận
<script>
var serviceUrl = "http://services.xiine.com/Xiine/Live/AccountService/rest/json/Login";
var userInfo = {
"IsNotEncrypted":true,
"Password":null,
"UserName":null
};
var loginSuccess = function(data, textStatus, jqXHR){
console.log("yay");
};
var loginError = function(){
console.log("oh no");
};
$.post(serviceUrl , userInfo, loginSuccess);
$.post(serviceUrl , loginSuccess);
</script>
Tôi cố gắng để thiết lập do tại sao nó là dịch vụ sẽ trở lại một cách chính xác một giá trị sai khi tôi không vượt qua dữ liệu người dùng:
$.post(serviceUrl , loginSuccess);
Trái ngược với khi tôi vượt qua dữ liệu người dùng, tại thời điểm đó nó cho lỗi POST 400 (Yêu cầu không hợp lệ).
$.post(serviceUrl , userInfo, loginSuccess);
Tôi chắc chắn nó phải làm với cách đối tượng JSON, userInfo, đang được xây dựng hoặc diễn giải, và tôi có thể đăng Fiddler 2 hoặc WireShark bãi, nếu điều đó sẽ giúp ích. Chỉ cần cho tôi biết ...
Tôi không thực sự có quyền truy cập để thay đổi bên WCF của dịch vụ, vì vậy hy vọng có điều gì đó mà tôi có thể làm để kết thúc công việc này.
Cảm ơn!
Sửa
tôi đã thêm một chút thông tin ... Rõ ràng, vấn đề là máy chủ đang phản hồi bằng các lỗi sau:
The server encountered an error processing the request. The exception message is 'The incoming message >has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml', >'Json'. This can be because a WebContentTypeMapper has not been configured on the binding. See the >documentation of WebContentTypeMapper for more details.'. See server logs for more details. The >exception stack trace is:
at System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.CompositeDispatchFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
Vì vậy, tôi nghĩ tôi cần phải hình làm thế nào để đưa đối tượng đi qua dây như một đối tượng JSON thông qua một phương thức JQuery.post().
biết thêm thông tin --- Một lần nữa ...
ok ... Không có app.config hoặc web.config, như vậy.
Đây là những gì tôi có thể nhận được như xa như các hợp đồng và mã và những gì không.
[ServiceContract]
public interface IAccount
{
[OperationContract]
bool Login(UserInformation user);
}
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class AccountService : IAccount
{
public bool Login(UserInformation user)
{
//stuff...
}
}
[DataContract]
public class UserInformation
{
[DataMember(IsRequired = true)]
public string UserName;
[DataMember(IsRequired = true)]
public string Password;
[DataMember(IsRequired = true)]
public bool IsNotEncrypted;
}
public interface IUserInformation
{
UserInformation UserInformation { get; set; }
}
Vui lòng đăng cấu hình dịch vụ WCF của bạn. –
Thật không may, tôi không có quyền truy cập vào nó ... – Joe