2011-08-29 5 views

답변

0

당신은 실제로이 속성

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

MVC3에서 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 문서입니다. 그래서 나는 그 문서를 일단 서비스에 postd 서비스에 저장 – latis

+0

webinvoke의 RequestFormat = WebMessageFormat.Xml 속성은 당신을 도울 것입니다 : [WebInvoke (Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Json)] –

+0

본문을 데이터 집합으로 가져 오는 데 여전히 문제가 있습니다. 어떤 예제가 있습니까? – latis

0

에서 샘플 방법은을 사용하여 웹 메소드에 인수를 전달할 수 있으며, 요청 객체는 컨트롤러에서 사용할 수 있습니다 본문의 내용은 InputStream 객체에서 사용할 수 있습니다. 이 코드는 나를 위해 일했습니다 :

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

도움이 되길 바랍니다.

관련 문제