WCF REST Webinvoke



  • Service

    [ServiceContract]
        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
        public class CustomConfigurationService
        {
    
        /*[OperationContract]
        [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]*/
        [WebInvoke(Method = "GET",
        BodyStyle = WebMessageBodyStyle.Bare,
        RequestFormat = WebMessageFormat.Xml, 
        ResponseFormat = WebMessageFormat.Xml)]
        [OperationContract]
        public string GetTransformValue(string name)
        {
            return "<order>" + name + "</order>";
        }
    }
    

    Client

    if (!IsAuthentificated)
    {
    return "";
    }
    string requestString = string.Format("http://crmtest.unistroyrf.ru/0/rest/CustomConfigurationService/GetTransformValue" +
    "?name={0}", param);
    HttpWebRequest request = HttpWebRequest.Create(requestString) as HttpWebRequest;
    request.Method = "GET";
    request.CookieContainer = AuthCookie;
    using (var response = request.GetResponse())
    {
    Stream receiveStream = response.GetResponseStream();
    StreamReader readStream = new StreamReader(receiveStream, Encoding.Default);

                Console.WriteLine("Response stream received.");
                Console.WriteLine(readStream.ReadToEnd());
                Console.ReadKey();
                response.Close();
                readStream.Close();
            }
    

    Turns out something like that.
    введите сюда описание изображения PERorder constituent12345 Gen/order
    Can we get the xml back somehow?



  • Don't come back. stringXElement:

    [OperationContract]
    public XElement GetTransformValue(string name)
    {
        return new XElement("order", name);
    }
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2