2011-04-12 2 views
0

WCF의 HTTP 포스트 서비스를 통해 문자열 값을 클라이언트에 반환하려고합니다.C# WCF 서비스를 통한 출력 값 반환

나는 다음을 통해 괜찮아 상태 코드를 반환 할 수 있습니다

WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.OK;

... 그러나 문자열 값을 클라이언트에 반환하는 방법에 대해서는 잘 모르겠습니다.

모든 포인터가 많이 감사하겠습니다.

감사

namespace TextWCF 
{ 
[ServiceContract] 
public interface IShortMessageService 
{ 
    [WebInvoke(UriTemplate = "invoke", Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest)] 
    [OperationContract] 
    void PostSMS(Stream input); 

} 
} 

[OperationBehavior] 
    public void PostSMS(Stream input) 
    { 

     StreamReader sr = new StreamReader(input); 
     string s = sr.ReadToEnd(); 
     sr.Dispose(); 
     NameValueCollection qs = HttpUtility.ParseQueryString(s); 

     string user = Convert.ToString(qs["user"]); 
     string password = qs["password"]; 
     string api_id = qs["api_id"]; 
     string to = qs["to"]; 
     string text = qs["text"]; 
     string from = qs["from"]; 

     WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.OK; 
     WebOperationContext.Current.OutgoingResponse. = HttpStatusCode.OK; 
    } 
+2

처럼 보이게하기 위해 메서드 서명을 변경합니다. 예를 들어 메소드 선언을 변경할 수 있습니다. 'string'을 반환하고 싶다면'public string PostSMS (Stream input)'을 사용하십시오. –

답변

2

당신은 닐이 지적한대로 방법이 실제로 뭔가를 반환해야합니다.

그래서 그냥 방법은`void`s을 설정

namespace TextWCF 
{ 
[ServiceContract] 
public interface IShortMessageService 
{ 
    [WebInvoke(UriTemplate = "invoke", Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest)] 
    [OperationContract] 
    string PostSMS(Stream input); 

} 
} 

[OperationBehavior] 
    public string PostSMS(Stream input) 
    { 

     StreamReader sr = new StreamReader(input); 
     string s = sr.ReadToEnd(); 
     sr.Dispose(); 
     NameValueCollection qs = HttpUtility.ParseQueryString(s); 

     string user = Convert.ToString(qs["user"]); 
     string password = qs["password"]; 
     string api_id = qs["api_id"]; 
     string to = qs["to"]; 
     string text = qs["text"]; 
     string from = qs["from"]; 

     WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.OK; 
     WebOperationContext.Current.OutgoingResponse. = HttpStatusCode.OK; 

     return "Some String"; 
    } 
+0

이 응답을 보내 주셔서 감사합니다. HTTP를 통해 공백 페이지를 보내려고합니다. 그 목적을 위해 작동할까요? 감사 – Nick