首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法使用ajax调用调用WCF

无法使用ajax调用调用WCF
EN

Stack Overflow用户
提问于 2014-03-26 18:08:16
回答 2查看 35关注 0票数 0

我是WCF的新手,用iCategoryMasterWCF.cs创建了一个名为CategoryMasterWCF.svc的WCFand文件,代码如下

代码语言:javascript
运行
复制
namespace InfraERP.WebServices
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "ICategoryMasterWCF" in both code and config file together.
[ServiceContract]
public interface ICategoryMasterWCF
{
    [OperationContract]
    [WebInvoke(ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat= WebMessageFormat.Json)]
    string DoWork();

    [OperationContract]
    [WebGet]
    [WebInvoke(ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json)]
    string sting(int id);

}


}

和具有如下代码的CategoryMasterWCF.svc.cs

代码语言:javascript
运行
复制
namespace InfraERP.WebServices
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "CategoryMasterWCF" in code, svc and config file together.
 [AspNetCompatibilityRequirements(RequirementsMode
= AspNetCompatibilityRequirementsMode.Allowed)]
public class CategoryMasterWCF : ICategoryMasterWCF
{

   public string DoWork()
    {
        return "Hello, It Worked! ";
    }

    public string sting(int id)
    {
        string _sting = "Number is " +id.ToString();
        return _sting;
    }

}
}

然后,我在我的aspx中添加了如下代码

代码语言:javascript
运行
复制
 $.ajax({
        type: "POST",
        url: '../WebServices/CategoryMasterWCF.svc/sting',
        contentType: "application/json; charset=UTF-8; charset-uf8",
        data: {id:"1"},
        processData: true,
        dataType: "json",
        success: function (msg) {
            alert(msg);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(textStatus + "---" + errorThrown);
        }
    });

出现的错误是“不支持的媒体类型”。

我不是一个在周转基金或Asp.net专家。我在web和stackoverflow中搜索了很多,并用提供的更改进行了测试,但没有找到好的结果。目前,我还没有对web配置进行任何更改。请帮我找一条出路。

EN

Stack Overflow用户

发布于 2014-03-26 18:27:47

您是否尝试过从ajax调用中删除contentType和dataType?

票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22657572

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档