我使用.net框架4.5创建了一个WCF应用程序。我需要调用WCF方法&在另一个MVC应用程序中相应地更新响应
请帮我同样的忙
以下是我的服务合同
public interface IService1
{
[OperationContract]
[WebInvoke (Method ="GET",ResponseFormat =WebMessageFormat.Json,BodyStyle =WebMessageBodyStyle.Wrapped,UriTemplate = "CBSResponse/{refno}/{amount}/{draccno}/{craccno}/{appid}")]
Posting_Result GetCBSResponse(string refno, string amount, string draccno, string craccno, string appid);
// TODO: Add your service operations here
}
// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class Posting_Result
{
[DataMember]
public string status { get; set; }
[DataMember]
public string remarks { get; set; }
[DataMember]
public DateTime modifieddt { get; set; }
}下面是我在控制器中的代码
HttpClient client = new HttpClient();
string url = obj.payment_url + obj.refno + "//" + obj.total.ToString() + "//" +obj.draccno + "//" + obj.craccno + "//Subh";
HttpResponseMessage wcfResponse = client.GetAsync(url).Result;
HttpContent stream = wcfResponse.Content;
var data = stream.ReadAsStringAsync();
// var paymentRequest = Request.Content.ReadAsAsync<PaymentRequest>().Result;
var result = data.Result;在结果变量中,我得到的响应低于
{"GetCBSResponseResult":{"modifieddt":"/Date(1466838186130+0530)/",“备注”:“”、“状态”:“S”}}
发布于 2016-06-25 18:13:49
我终于找到了解决办法
我更改了服务契约以生成JSON,而不是XML。
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "CBSResponse/{refno}/{amount}/{draccno}/{craccno}/{appid}")]
Posting_Result GetCBSResponse(string refno, string amount, string draccno, string craccno, string appid);在客户端,我使用了以下代码
var result = wcfResponse.Content.ReadAsStringAsync().Result;
var myclass = JsonConvert.DeserializeObject<dynamic>(result);
CBS_Response user = JsonConvert.DeserializeObject<CBS_Response>(result);https://stackoverflow.com/questions/38025984
复制相似问题