none
WCF收不到POST传值 RRS feed

  • 问题

  • 调用方法如下 [OperationContract(Name = "SendMessage")] [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, UriTemplate = "SendMessage?message={message}", BodyStyle = WebMessageBodyStyle.Wrapped)] String SendMessage(String message); JAVA中调用: HttpPost post = new HttpPost(BASE_URL+"/SendMessage?message="); List<NameValuePair> value=new ArrayList<NameValuePair>(); value.add(new BasicNameValuePair("message","hello")); try { HttpEntity httpcode=new UrlEncodedFormEntity(value,HTTP.UTF_8); post.setEntity(httpcode); HttpResponse httpResponse = client.execute(post); statusCode = httpResponse.getStatusLine().getStatusCode(); if(statusCode==HttpStatus.SC_OK) { result = retrieveInputStream(httpResponse.getEntity()); } }catch(Exception e) { } 可以调用,但String SendMessage(String message);中message值为空
    2011年12月6日 11:28

全部回复

  • Hi,


    看你上面列出的代码,好像没有什么问题。你可以设置一个断点来调试HttpReponse的StatusCode是否为SC_OK(成功执行),你看下传递的URL是否正确。


    Regards


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework
    2011年12月8日 2:49
    版主