2011-02-28 72 views
0

當我向一個restful wcf服務進行標準的Get Request調用時,它將返回一個內容類型爲「application/xml」的應用程序。供應商要求我們發送內容類型爲「text/xml」的內容。如何在wcf中切換這個?它是一個屬性?text/xml從休息中返回調用

的調用是這樣的:

[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; 
    } 
} 

回答

0

您可以覆蓋內容類型:

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

1

不要嘗試使用WCF來調用RESTful服務。只需使用HttpWebRequest或HttpClient,這樣你就可以控制你的請求。

+0

HttpClient的包括在WCF休息初學者工具包預覽2 http://aspnet.codeplex.com/releases/view/24644 –

+0

@Joey那了HTTPClient不再支持。有一個新的http://wcf.codeplex.com –

+0

謝謝。似乎WCF中的REST堆棧不斷變化......忘記了Glen接管了它。 –