WCF 400 错误请求
我创建了一个简单的函数
[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
我收到此呼叫的 400 错误请求。我希望我在这里没有做完全错误的事情。我应该能够从浏览器访问 WCF 服务,对吧? 在我想到发帖之前,我尝试了很多。但我无法让这个基本的事情发挥作用,这让我很沮丧。
编辑&更新 现在我正处于这个阶段。服务页面告诉我元数据服务已禁用,并要求我插入以下文本
<serviceMetadata httpGetEnabled="true" />
我插入了文本 - 但它仍然显示相同的文本!现在这变得太混乱了..
I created a simple function
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json)]
string Start();
Definition,
public String Start()
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
return serializer.Serialize("Check");
}
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
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..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将 POST 改为 GET 并重新启动请求
Try to change POST with GET and restart the request
对我有用。我创建了 WCF 休息服务。
我使用的 URL 看起来像 http://localhost:8080/Service1/Start
这是代码:
Works for me. I created WCF Rest Service.
I use URL which looks like http://localhost:8080/Service1/Start
Here is the code: