WCF 400错误的请求 [英] WCF 400 Bad Request

查看:225
本文介绍了WCF 400错误的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个简单的函数

I created a simple function

       [OperationContract]
       [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json)]
       string Start();

定义,

       public String Start()
       {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            return serializer.Serialize("Check");
       }

从使用Javascript / jQuery的浏览器,
HTTP://localhost/service1.svc 告诉我,我创建了一个服务和其他信息..看起来罚款。

我试图把这种用
HTTP://localhost/service1.svc/Start

From browser using Javascript/Jquery, http://localhost/service1.svc tells me I have created a service and all other info.. Looks fine.
I'm trying to call this using http://localhost/service1.svc/Start

我得到这个呼叫400错误的请求。我希望我没有做一些完全错误的在这里。我应该能够从浏览器中访问WCF服务?
我试着找了很多以前我以为张贴。但我无法得到的工作是令人沮丧的我这个基本的东西。

I get a 400 bad request for this call. I hope I'm not doing something totally wrong here. I should be able to access WCF service from browser right? I tried looking a lot before I thought of posting. But I'm unable to get this basic thing working is frustrating me.

修改&安培;更新
现在我在这个阶段。服务页面告诉我,元数据服务被禁用,并要求我插入下面的文本

EDIT & UPDATE Now I'm at this stage. The service page is telling me that the metadata service is disabled and is asking me to insert the following text

   <serviceMetadata httpGetEnabled="true" />

我插入的文本 - 但它毕竟显示了同样的文字!现在,这是越来越太混乱了。

I inserted the text - but still it shows the same text!! This is getting too confusing now..

推荐答案

我的作品。我创建WCF REST服务。

Works for me. I created WCF Rest Service.

我使用的URL看起来像的http://本地主机:8080 /服务1 /开始

I use URL which looks like http://localhost:8080/Service1/Start

下面是code:

using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Web.Script.Serialization;

namespace WcfRestService1
{
    // Start the service and browse to http://<machine_name>:<port>/Service1/help to view the service's generated help page
    // NOTE: By default, a new instance of the service is created for each call; change the InstanceContextMode to Single if you want
    // a single instance of the service to process all calls.   
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    // NOTE: If the service is renamed, remember to update the global.asax.cs file
    public class Service1
    {
        [OperationContract]
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json)]
        public string Start()
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            return serializer.Serialize("Check");
        }
    }
}

这篇关于WCF 400错误的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆