2011-08-29 56 views

回答

0

实际上,你可以传递参数来使用这个属性

[WebGet(UriTemplate = "users/{username}")] 

这里是msdn

[WebGet(UriTemplate = "users/{username}")] 
[OperationContract] 
User GetUserAccount(string username) 
{ 
    if (!IsUserAuthorized(username)) 
    { 
     WebOperationContext.Current.OutgoingResponse.StatusCode = 
      HttpStatusCode.Unauthorized; 
     return; 
    } 
    User user = FindUser(username); 
    if (user == null) 
    { 
     WebOperationContext.Current.OutgoingResponse.SetStatusAsNotFound(); 
     return null; 
    } 
    return user; 
} 
+0

感谢您的回复。忘记添加请求体是一个xml文档。所以我需要将该文档保存到SQL一旦postd服务 – latis

+0

WebForvoke的Web应用程序= WebMessageFormat.Xml属性应该帮助您.eg:[WebInvoke(Method =“POST”,BodyStyle = WebMessageBodyStyle.Wrapped,RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Json)] –

+0

我仍然有麻烦进入数据集的身体。你有什么例子吗? – latis

0

在MVC3的样品的方法您的Web方法,Request对象是在控制器中可用,在InputStream对象中可以使用正文的内容。此代码为我工作:

 this.Request.InputStream.Position = 0; 
     var xmlContent = new System.IO.StreamReader(this.Request.InputStream).ReadToEnd(); 

希望有所帮助。

相关问题