【发布时间】:2014-07-17 08:06:58
【问题描述】:
我一直在努力解决这个问题以找到它的根源,但还没有运气。我的 WebAPI 在 IIS 中自己的应用程序池中运行,并且这些操作假定返回 XML 和 JSON,但它只返回 JSON。更奇怪的是它在其他 PC 上运行良好,所以我的猜测是我的 IIS 一定有问题,或者我缺少某种配置。如果我使用 Visual Studio Server 而不是 IIS,它工作得非常好。
API 配置:
//Added to support .net1.1 clients
config.Formatters.XmlFormatter.UseXmlSerializer = true;
config.Formatters.JsonFormatter.UseDataContractJsonSerializer = true;
config.Formatters.Add(new FormUrlEncodedMediaTypeFormatter());
数据属性:
/// <summary>
/// Unique Transaction ID
/// </summary>
private int TransactionID;
[XmlElement(Type = typeof(int))]
public int fTransactionID
{
get{return TransactionID;}
set{TransactionID = value;}
}
请求标头
// Create a WebRequest to the remote site
WebRequest myWebClient = WebRequest.Create(uri);
myWebClient.ContentType = "application/xml";
myWebClient.Method = method;
编辑
API 方法
/// <summary>
/// Return Rebate Reversal Transactions
/// </summary>
/// <param name="FromDate"></param>
/// <param name="ToDate"></param>
/// <param name="PracticeID"></param>
/// <returns></returns>
[AttributeRouting.Web.Http.GET("RebateReversalTransaction/{FromDate}/{ToDate}/{PracticeID}")]
public GetRebateReversalTransactionResponse GetReversalTransaction(int FromDate, int ToDate, int PracticeID)
{
GetRebateReversalTransactionResponse reversalResponse = new GetRebateReversalTransactionResponse();
service = new PPNRebateSystemService();
reversalResponse = service.GetPracticeRebateReversalTransactions(FromDate, ToDate, PracticeID);
return reversalResponse;
}
【问题讨论】:
-
我假设请求的
ContentType是application/xml? -
你有没有运行过 HTTP 嗅探器?
-
我在 Chrome 上使用 Postman 来测试我的 api,即使我指定了内容类型它仍然不返回 xml
-
您是否尝试将 WebRequest 上的“Accept:application/xml”标头设置为 API?
-
@Balachandra 是的,我有,但仍然没有运气。我认为问题在于 IIS 级别
标签: c# iis asp.net-web-api