2011-01-06 3 views
5

私の問題は次のとおりです。

httppostの本文にプレーンテキストを受け入れるWebサービスを構築する必要があります。
私はwcfを使いたいと思っていますが、wcfはxml/jsonに対してのみ作成されているようです。プレーンテキストをWCFサービスに投稿するにはどうすればいいですか?つまり、XMLタグでラップされていないのですか?

誰かがhttp投稿を通じてプレーンテキストを投稿するために使用できる方法はありますか?
私は石鹸を使用することはできませんまたはxmlタグ内のテキストをラップする、私は特定のガイドラインに従う必要があります既存のサービスコンシューマーと互換性があります。

ありがとうございます。

+0

でのparamストリームXXX

であなたのメソッドを呼び出す方法、既存のサービスが実装されていますか? – Lazarus

答えて

0

トリックはあなたがiContract

[WebInvoke(Method = "POST", 
    UriTemplate = "InterpSvcTest", 
    BodyStyle = WebMessageBodyStyle.Bare)] // this is key for combining params with Stream 

Stream InterpretORUTest(Stream ORU); 
あなたのWebServiceクラスで

public Stream InterpretORUTest(Stream ORUMessageStream) 
    { 
     string hl7 = StreamToString(ORUMessageStream); 

     return StringToStream(hl7); 

    } 

    public Stream StringToStream(string s) 
     { 
      return new MemoryStream(Encoding.UTF8.GetBytes(s)); 

     } 

     public string StreamToString(Stream ms) 
     { 
      try 
      { 
       using (ms) 
       { 
        var sr = new StreamReader(ms); 
        var myStr = sr.ReadToEnd(); 
        sr.Dispose(); 
        return myStr; 
       }; 
      } 
      catch (Exception e) 
      { 
       c.WriteToLog("StreamToString error - " + e.Message); 
       return ""; 

      } 

     } 
関連する問題