寻找关于wcf 4休息服务的一些指导,该服务基于VS2010中的WCF REST模板40(CS)扩展.我花了最近几天试图让这个bug工作,审查其他帖子,而我已经接近,我似乎无法越过终点线.经过很多挫折之后,它终于点击了服务并发布了(使用fiddler请求构建器),但是方法参数是null,但它在请求构建器中正确设置.我猜这可能是配置问题,但随着截止日期的临近,我没有时间进行更多的研究.FWIW,在调试中,jsonstring变量为null.自我肯定是一个菜鸟问题,因为这是第一次通过REST为我,任何帮助将不胜感激!
提前致谢.
web.config中
<system.web>
'<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
</system.webServer>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
的global.asax.cs
public class Global : HttpApplication
{
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes();
}
private void RegisterRoutes()
{
RouteTable.Routes.Add(new ServiceRoute("Scoring", new WebServiceHostFactory(), typeof(ScoringSvc)));
}
}
Run Code Online (Sandbox Code Playgroud)
服务代码
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class ScoringSvc
{
[OperationContract]
[WebInvoke
(Method = "POST",
BodyStyle …Run Code Online (Sandbox Code Playgroud) 我有一个WCF消息(Channels.Message),我正在尝试使用.GetBody()提取正文.但是,我注意到我只能做一次,如果我再次尝试使用"GetBody <>",我会得到:"这条消息不能支持操作,因为它已被读取."
知道如何重新阅读邮件正文?
谢谢
我在.net 4中运行了一个REST WCF服务,我测试了它正在运行的Web服务,并接受我做的HttpRequest.但是我在尝试访问Web服务中的HttpRequest主体时遇到了问题.我已经尝试使用Fiddler和我的WinForm应用程序发送附加在HttpRequest上的随机大小的数据,我似乎无法在运行时找到任何可以找到我的请求主体的对象.我最初的本能是查看HttpContext.Current.Request.InputStream但该属性的长度为0,所以我试着查看IncomingWebRequestContext该对象甚至没有方法也没有属性来获取HttpRequest的主体.
所以我的问题是,有没有办法在WCF中访问HttpRequest请求体?
PS:请求体内的数据是JSON字符串,对于响应,它也会将响应体内的数据作为JSON字符串返回.
json ×2
wcf ×2
.net-4.0 ×1
c# ×1
httprequest ×1
message ×1
post ×1
rest ×1
wcf-rest ×1
web-services ×1