title: Getting return type invalid error while trying to call WCF webservice 4.0
body: <p>I am trying to write and call WCF web service, below are the details:</p>
  
  <p><strong>Web.config:</strong></p>
  
  <pre><code>&lt;add relativeAddress="FetchData.svc" service="WCF.Services.FetchData" /&gt;
  
  &lt;service name="WCF.Services.FetchData"&gt;
      &lt;endpoint address="" binding="webHttpBinding" bindingConfiguration="" name="FetchData" contract="WCF.Services.FetchData" /&gt;
  &lt;/service&gt;
  </code></pre>
  
  <p><strong>FetchData Class (Sample Code):</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.ServiceModel;
  using System.ServiceModel.Activation;
  using System.Web;
  using System.Xml;
  using Webservices.Services;
  using Data = Webservices.Data;
  using System.ServiceModel.Web;
  using System.IO;
  using System.Net;
  using System.ServiceModel.Channels;
  using System.Web.UI;
  using System.Text;
  
  
  namespace WCF.Services
  {    
      [ServiceContract(Namespace = "urn:WCF.Services.FetchData")]
      public class FetchData
      {
          Data.GetConnect mConnect = new Data.GetConnect();
          private Message RetrievePublishedData(String pub, int number)
          {
              String strOutput = String.Empty; 
              if (!String.IsNullOrEmpty(pub))
              {
                  Boolean pubURLExists = mConnect.CheckPubUrlExists(pub);
  
                  if (!pubURLExists)
                  {
                      WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotFound;
                      return WebOperationContext.Current.CreateTextResponse(String.Format("Requested publication '{0}' is not available.", pub), MimeTypes.TextPlain, Encoding.UTF8);
                  }
                  using (StringWriter sw = new StringWriterEncoding())
                  {
                      using (HtmlTextWriter hw = new HtmlTextWriter(sw))
                      {
                          hw.RenderBeginTag(HtmlTextWriterTag.Html);
                          XmlNode publishedData = mConnect.GetPublishedData(pub, number);
                          hw.RenderEndTag();
                      }
                      return WebOperationContext.Current.CreateTextResponse(sw.ToString(),MimeTypes.TextHTML, Encoding.UTF8);
                  }
              }
              return WebOperationContext.Current.CreateTextResponse(strOutput, MimeTypes.TextHTML, Encoding.UTF8);
          }
          [OperationContract]
          [WebGet(UriTemplate = "/published/{number}/{*pub=default}")]
          public Message FetchPublished(String pub, int number)
          {
             return RetrievePublishedData(pub, number);
          }
      }
  }
  </code></pre>
  
  <p>Now when I am trying to browse the web service, I am getting below error:</p>
  
  <p>Web Service URL - <code>http://localhost:8082/FetchData.svc</code></p>
  
  <p><strong>Error:</strong>
  <em>The operation 'FetchPublished' could not be loaded because it has a parameter or return type of type System.ServiceModel.Channels.Message or a type that has MessageContractAttribute and other parameters of different types. When using System.ServiceModel.Channels.Message or types with MessageContractAttribute, the method must not use any other types of parameters.</em></p>
  
  <p><strong>Edit:</strong></p>
  
  <pre><code>namespace WCFWebServices
  {
      [ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
       [ServiceContract(Namespace = "urn:WCFWebServices.fetchPush")]
          public class FetchData
          {
           [MessageContract]
           public class RetrievePublishedDataInput
           {
               [MessageBodyMember]
               public String pub;
               [MessageBodyMember]
               public String number;
           }
              private Message RetrievePublishedData(RetrievePublishedDataInput input)
              {
                  String strOutput = String.Empty;
                  String pub = input.pub;
                  String number = input.number;
                  if (!String.IsNullOrEmpty(pub))
                  {
                      Boolean pubURLExists = true;
  
                      if (!pubURLExists)
                      {
                          WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotFound;
                          return WebOperationContext.Current.CreateTextResponse(String.Format("Requested publication '{0}' is not available.", pub), "application/plain; charset=utf-8", Encoding.UTF8);
                      }
                      using (StringWriter sw = new StringWriter())
                      {
                          using (HtmlTextWriter hw = new HtmlTextWriter(sw))
                          {
                              hw.RenderBeginTag(HtmlTextWriterTag.Html);
  
                              hw.RenderEndTag();
                          }
                          return WebOperationContext.Current.CreateTextResponse(sw.ToString(), "application/html; charset=utf-8", Encoding.UTF8);
                      }
                  }
                  return WebOperationContext.Current.CreateTextResponse(strOutput, "application/html; charset=utf-8", Encoding.UTF8);
              }
              [OperationContract]
              [WebGet(UriTemplate = "/publishedData/{number}/{pub=default}")]
              public Message FetchPublished(RetrievePublishedDataInput input)
              {
                  return RetrievePublishedData(input);
              }
          }      
  }
  </code></pre>