English 中文(简体)
是否需要申请/x-www-form-urlencoded in a WCF ReSTful Service?
原标题:Does the Content-Type of a POST or PUT request need to be application/x-www-form-urlencoded in a WCF ReSTful service?
  • 时间:2010-01-20 15:22:49
  •  标签:
  • c#
  • wcf
  • rest

我试图做的是,似乎简单:通过请求机构派出一些POX,拥有WCF服务程序,并退回了201个地位法。 在我的服务合同中,我确定了以下方法:

    [WebInvoke(Method = "PUT", UriTemplate = "/content/add", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Xml, RequestFormat=WebMessageFormat.Xml)]
    [OperationContract]
    Stream AddContent(Stream input);

这里的斜体是 t的;我可以很容易地用POST取代PUT,得出同样的结果。 上述方法的实施如下:

    public Stream AddContent(Stream input)
    {
        WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Created;
    }

由于这种方法的实际效果不大,我忽略了所有程序法。 为了测试这一功能,我向Fiddler提出以下要求:

 User-Agent: Fiddler
 Host: myhost.com
 Content-Length: 771
 Content-Type: text/xml && application/xml; charset: utf8
 <xmlDataGoesHere></xmlDataGoesHere>

我知道,Type的供给价值是不正确的,我刚刚利用这一价值来说明我所尝试的内容——Type。 如果我点击菲德勒的紧急情况,我的服务是400份巴德尔要求。 值得注意的是,我的服务方法实际上并没有在这种秘密中受到打击,而这一请求甚至在到达之前就已经消失。 因此,经过大量阅读和删除过程之后,我改变了内容提要:

 Content-Type: application/x-www-form-urlencoded

如果我执行菲德勒要求,则从我的服务中恢复的《地位法》即为201项。 难道我不知道我为什么会把内容提要定在什么东西,但URLEncoded? 我曾尝试在服务合同中打碎机和要求购物财产,但结果没有影响。 谁能说明为什么发生这种情况?

最佳回答

奥基组织我已经指出这一点,我提出的问题是“按设计”。 我发现WCF员额“Raw”方案拟订模式——在上接收任意数据。 这导致了解决办法。 这里的解决办法是创造我自己的习惯,随着博客所指出的时间的推移将原产地归还。 感谢一切帮助。

问题回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签