text / xml从休息调用返回

时间:2011-02-28 18:22:40

标签: wcf rest

当我对一个宁静的wcf服务进行标准的Get Request调用时,它返回的内容类型为“application / xml”。供应商要求我们发送内容类型为“text / xml”。如何在wcf中切换它?这是属性吗?

电话是:

[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, Namespace = "")]
[XmlSerializerFormat(Style = OperationFormatStyle.Document, Use=OperationFormatUse.Literal)]
public class Player
{

    [WebGet(UriTemplate = "{id}")]
    public string GetTestDetailsRequest(string id)
    {
        TestService.TestServiceClient testServiceClient = new TestServiceClient();
        string xml = testServiceClient.GetTestDetailsRequest(Guid.Parse(id));
        return xml;
    }
}

2 个答案:

答案 0 :(得分:1)

不要尝试使用WCF来调用RESTful服务。只需使用HttpWebRequest或HttpClient,就可以控制您的请求。

答案 1 :(得分:0)

您可以覆盖内容类型:

WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";