简体   繁体   English

ajax调用sharepoint托管的wcf服务错误请求

[英]ajax call sharepoint hosted wcf service bad request

I have a WCF service hosted in Sharepoint 2010 (therefore no config file necessary --> ServiceHost Factory set to MultipleBaseAddressWebServiceHostFactory). 我在Sharepoint 2010中托管了WCF服务(因此无需配置文件-> ServiceHost Factory设置为MultipleBaseAddressWebServiceHostFactory)。

My service interface: 我的服务界面:

[OperationContract]
    [WebInvoke(
        Method = "POST",
        BodyStyle = WebMessageBodyStyle.WrappedRequest,
        RequestFormat = WebMessageFormat.Json,
        ResponseFormat = WebMessageFormat.Json)]
    List<Course> GetAllCoursesByPerno(string empPerno);

My ajax call: 我的ajax电话:

var input = $j("#perno").val();
    $j.ajax({
        type: "POST",
        url: "/_vti_bin/Project/Service.svc/GetAllCoursesByPerno",
        dataType: "json",
        //data: input,
        data: '{"empPerno": "' + input + '"}',
        contentType: "application/json; charset=utf-8",
        processData: true,
        success: function (data) {
            var courseData = data;
        },
        error: function (e) {
            alert(e.statusText);
        }
     });

My method: 我的方法:

public List<Course> GetAllCoursesByPerno(string empPerno)
{
    .
    .
    .
    .
}

I get a 400 Bad Request each time. 我每次都会收到400错误请求。 I've tried every which way to compose the data; 我已经尝试了各种方式来组合数据。

data: '{"empPerno": "' + input + '"}',

data: JSON.stringify({ empPerno : input }),

But no cigar. 但是没有雪茄。 Any help would be appreciated! 任何帮助,将不胜感激!

Thanks 谢谢

Use Microsoft ajax library for calling. 使用Microsoft ajax库进行调用。 This also avoid DateTime deserializing issues 这也避免了DateTime反序列化问题

Sys.Net.WebServiceProxy.invoke('/_vti_bin/YourSubfolder/SearchService.svc',
        'EmptyMethod',
        false,
        {data: 'client data'},
        function () {
            console.log('Success', arguments);
        },
        function () {
            console.log('Eroor', arguments);
        }, this);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM