WCF服务 - 绝对基础 - 帮助? [英] WCF Service - the absolute basics - help?
问题描述
我已经在这2天了,开始感到沮丧。我想创建一个简单的"hello world"。我可以"获取"的WCF服务使用jQuery。无论我做什么,我总是最终得到400 Bad Request。我已经搜索过MSDN文档,VS2008帮助,尝试了很多教程,然后是来自Rick Strahl等各种博主的代码,最近这篇文章http://www.dennydotnet.com/post/2008/03/03/Passing-a- JSON-object-to-a-WCF-service-with-jQuery.aspx。
我可以在端点http://localhost/WCFService2/Service.svc浏览我的服务,它生成服务带文字的屏幕:
您已经创建了一项服务。
要
测试此服务,您需要创建一个客户端并使用它来调用
服务...
但是,我是不打算编写.NET客户端来使用该服务。相反,我将直接从Ajax请求调用服务。我用[WebInvoke(Method =" GET")]]修饰了方法,并将服务配置为允许AspNetCompatibility。我的理解是,我应该能够浏览到http://localhost/WCFService2/Service.svc/GetData并返回一些xml。当我尝试这一切时,我得到的是400 Bad Request。
我在这里缺少什么?我可以发布代码,但我的最新版本是来自VisualStudio 2008的WCFService模板,修改了GetData方法以返回包含"hello world"的字符串。
干杯,
T
我设法取得了一些进展。我已经创建了一个简单的.svc文件:
< %@ ServiceHost 语言 = " C#" Debug = " true" 服务 = " adbeast.JobProcessor.MonitorService" 工厂 = " System.ServiceModel.Activation.WebScriptServiceHostFactory" %< font style ="color:blue">>
Hi, I've been at this for 2 days and starting to get frustrated. I want to create a simple "hello world" WCF service that I can "GET" using jQuery. No matter what I do I always end up with 400 Bad Request. I have scoured MSDN documentation, VS2008 help, tried numerous tutorials, followed along with code from various bloggers like Rick Strahl and most recently this post http://www.dennydotnet.com/post/2008/03/03/Passing-a-JSON-object-to-a-WCF-service-with-jQuery.aspx.
I am able to browse to my service at the endpoint http://localhost/WCFService2/Service.svc which produces the Service screen with the text:You have created a service.
To test this service, you will need to create a client and use it to call the service...
However, I am not going to be writing a .NET client to consume the service. Instead I will be calling the service directly from an Ajax request. I have decorated the method with [WebInvoke(Method = "GET")] and configured the service to allow AspNetCompatibility. My understanding is that I should then be able to browse to http://localhost/WCFService2/Service.svc/GetData and return some xml. When I try this all I get is 400 Bad Request.
What am I missing here? I can post code, but my latest incarnation is the WCFService template from VisualStudio 2008 with the GetData method modified to return a string containing "hello world".
Cheers,
T
解决方案I've managed to make some headway. I've created a simple .svc file like so:
<%@ ServiceHost Language="C#" Debug="true" Service="adbeast.JobProcessor.MonitorService" Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory" %>
这篇关于WCF服务 - 绝对基础 - 帮助?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文