私はRESTベースのWCF Webサービスを持っています。誰も私がこの残りのベースのwebserviceのhttp要求を手動で構築する手助けができますか?
契約は次のとおりです。
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Xml)]
string EchoWithPost(string message);
メッセージは次のとおりです。
public string EchoWithPost(string s)
{
return "ECHO with POST : You said " + s;
}
私はPOSTを経由して応答を取得するためにウェブチャネルファクトリを使用し、それが動作します。
//5) manually post to the REST service
//Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create(urlOfService + "/rest/EchoWithPOST");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "<EchoWithPost xmlns="http://tempuri.org"><message>Hello</message><EchoWithPost>";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/xml";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream();
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
// Get the response.
WebResponse response = request.GetResponse();
// Display the status.
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
Console.WriteLine(responseFromServer);
// Clean up the streams.
reader.Close();
dataStream.Close();
response.Close();
:私は、次のリクエストのロジックを構築した。このことから)コンテンツタイプ
を
1)、そのXMLが 2に送信されます。私は、メッセージをタップするのwiresharkを使用し、私はいくつかの重要な事柄を見ることができます
は、しかし、私は言うラインを打ったとき:
dataStream = response.GetResponseStream();
私は次のエラーを取得する:
"リモートサーバーからエラーが返されました:(400)Bad Request"
私が必要とするものを手伝ってもらえますか?人と人との対話のためのPOSTリクエストを手動で作成する方法を教えてもらえますか?このRESTベースのサービス。
本当にありがとうございました。他に何を試してみるか分かりません。
こんにちはヴィトー、これは基本的に私は両方のコードセクションを見て、私が取る必要がすべてのxmlをきれいにしたので、ありがとう。私はSOAP UIを取得し、それを使って遊びます – Exitos