2012-04-23 18 views
2

私はREST APIで作業する必要があるプロジェクトに取り組んでいます。 APIでは、入力パラメーターとしてDTOが必要です。私は、次の方法で、この方法にデータを送信しようとしているC#REST API:xml from post data

[OperationContract] 
     [WebInvoke(Method = "POST", UriTemplate = "campaign/create?session={sessionkey}", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Xml)] 
     [XmlSerializerFormat(Style = OperationFormatStyle.Document, Use = OperationFormatUse.Literal)] 
     FeedbackDTO PersistCampaign(string sessionkey, CampaignDTO PaycentoCampaign); 

:デバッグの時間後

public static HttpWebResponse DoHttpWebRequest(String url, String method, string data) 
{ 
    HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest; 
    req.KeepAlive = false; 
    req.ContentType = "application/xml"; 
    req.Method = method; 
    if ((method.Equals("POST") || method.Equals("PUT")) && data != null) 
    { 
     byte[] buffer = Encoding.UTF8.GetBytes(data); 
     Stream PostData = req.GetRequestStream(); 
     PostData.Write(buffer, 0, buffer.Length); 
     PostData.Close(); 
    } 
    return req.GetResponse() as HttpWebResponse; 
} 

私は問題はのDateTime proprtiesによって引き起こされることがわかりました。私はXMLを作成し、プロパティごとにプロパティを「手動で」作成し始めました。

sb.Append("<Startdate>").Append(HttpUtility.HtmlEncode(Startdate.ToString(Helper.DATE_FORMAT_STRING))).Append("</Startdate>"); 

toStringにフォーマット(ddMMyyyy)を追加しようとしましたが、依然として不正なリクエストが発生しています。 ASP.NETがDTOに解析できるように、DateTimeプロパティをXMLにどのように追加する必要がありますか?

ものは私が試した:

  • StartDate.ToLongDateString()
  • StartDate.ToString()
  • StartDate.toString( "ddhhyyyy")
  • StartDate.Ticksを
+0

@HenkHoltermanこのサービスは有効なサービスであるとは認識しません。 – Reinard

+0

試しにGetResponseをラップし、この質問に対する回答のコードを使用してください。http://stackoverflow.com/questions/9948367/cant-get-actual-error-in-response-for-rest-request-fiddler-shows- me-more-error/9948511#9948511サーバーからの実際の応答を取得して投稿することもできます。 – JamieSee

+0

@JamieSeeローカル変数を。 – Reinard

答えて

1

StartdDate.toString( "s")がトリックを行いました。