Im은 WCF Web API를 사용하여 프로그래밍 된 일부 정보를 내 API에 게시하려고합니다. 클라이언트에서 restful을 사용하고 있습니다. 이것은 restful 서비스를위한 휴식 클라이언트입니다. 그러나 요청에 일부 매개 변수를 추가하여 게시하려고하면 서비스의 post 메서드가 호출되지 않고 클라이언트의 내 응답 개체가 500 상태 (내부 서버 오류)를 얻지 만 내가 ' 매개 변수를 추가하면 요청이 서비스에 노출 된 게시 메소드에 도달합니다. 나는 서비스에서 게임 객체가 채워됩니다 그래서 내 요청에 매개 변수를 추가 할 필요가restsharp를 사용하는 WCF 웹 API 서비스의 http 게시
[WebInvoke(UriTemplate = "", Method = "POST")]
public HttpResponseMessage<Game> Post(Game game, HttpRequestMessage<Game> request)
{
if (null == game)
{
return new HttpResponseMessage<Game>(HttpStatusCode.BadRequest);
}
var db = new XBoxGames();
game = db.Games.Add(game);
db.SaveChanges();
HttpResponseMessage<Game> response = new HttpResponseMessage<Game>(game);
response.StatusCode = HttpStatusCode.Created;
var uriBuilder = new UriBuilder(request.RequestUri);
uriBuilder.Path = string.Format("games/{0}", game.Id);
response.Headers.Location = uriBuilder.Uri;
return response;
}
다음은 서비스에 대한 코드의
[HttpPost]
public ActionResult Create(Game game)
{
if (ModelState.IsValid)
{
var request = new RestRequest(Method.POST);
var restClient = new RestClient();
restClient.BaseUrl = "http://localhost:4778";
request.Resource = "games";
//request.AddParameter("Name", game.Name,ParameterType.GetOrPost); this is te line when commented everything works fine
RestResponse<Game> g = restClient.Execute<Game>(request);
return RedirectToAction("Details", new {id=g.Data.Id });
}
return View(game);
}
:
다음은 클라이언트의 코드입니다 하지만 매개 변수를 추가하려고 할 때마다 서비스가 중단되는 경우이를 수행하는 방법을 모른다.
클라이언트와 서버 모두 .NET MVC 3 응용 프로그램이라는 것을 잊어 버렸습니다.
도움을 주시면 감사하겠습니다. 미리 감사드립니다.
문제가 해결되었습니다. 고마워요! – Daniel