开发者

text/xml return from rest call

开发者 https://www.devze.com 2023-02-13 18:44 出处:网络
When I make a standard Get Request call to a restful wcf service it returns with a content type of \"application/xml\". A vendor is asking we send with a content type of \"text/xml\". How do I switch

When I make a standard Get Request call to a restful wcf service it returns with a content type of "application/xml". A vendor is asking we send with a content type of "text/xml". How do I switch this in wcf? Is it an attribute?

The call is this:

[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.GetTestDetails开发者_C百科Request(Guid.Parse(id));
        return xml;
    }
}


Don't try and use WCF to call RESTful services. Just use HttpWebRequest or HttpClient, that way you will have control over your request.


You can override the content type:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消