locked
Getting error on PUT METHOD( The remote server returned an error: (404) Not Found.) RRS feed

  • Question

  • User-952569294 posted

    Hello

    I am quit new to wcf i am trying to create wcf service that get data from sql server .

    All method are working fine inn my consuming application the only issue when trying to update the record i don't understand why its happening

    Here is Code for update method:

    WCF: 

    [OperationContract]
    [WebInvoke(Method = "PUT",
    ResponseFormat = WebMessageFormat.Xml,
    RequestFormat = WebMessageFormat.Xml,
    BodyStyle = WebMessageBodyStyle.Bare,
    UriTemplate = "xmlput/{id}")]
    string XMLDataPut(string Id,Stream data);

    consuming:


    string url = "http://localhost/WcfRest/RestServiceImpl.svc/xmlput/3560";
    string specchar = "/";
    string Id = url.Substring(url.LastIndexOf(specchar) + 1);


    ASCIIEncoding encoding = new ASCIIEncoding();
    string strResult = string.Empty;


    string SampleXml = @"<Person>" +
    "<FirstName>Updated Record</FirstName>" +
    "<Grammys>updated grammys</Grammys>" +
    "<LastName>updated</LastName>" +
    "<Id>" + Id + "</ID>" +
    "</Person>";
    string postData = SampleXml.ToString();

    byte[] data = encoding.GetBytes(postData);

    HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);
    webrequest.Method = "PUT";


    webrequest.ContentType = "application/x-www-form-urlencoded";


    webrequest.ContentLength = data.Length;


    Stream newStream = webrequest.GetRequestStream();
    newStream.Write(data, 0, data.Length);
    newStream.Close();


    HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse();


    Encoding enc = System.Text.Encoding.GetEncoding("UTF-8");


    StreamReader loResponseStream = new StreamReader(webresponse.GetResponseStream(), enc);


    strResult = loResponseStream.ReadToEnd();


    loResponseStream.Close();


    webresponse.Close();


    strResult = strResult.Replace("</string>", "");

    Getting Error on webResponce

    Thanks

    Vinkesh

    Tuesday, June 4, 2013 2:48 AM

All replies

  • User260886948 posted

    Hi,

    The error "The remote server returned an error: (404) Not Found." is general error, please try to enable Tracing to troubleshoot the issue. Add below in WCF service configuration and open this trace file using Service Trace Viewer tool.

    <system.diagnostics>
      <sources>
          <source name="System.ServiceModel.MessageLogging"
                   switchValue="Information, ActivityTracing, Error">
            <listeners>
                     <add name="messages"
                     type="System.Diagnostics.XmlWriterTraceListener"
                     initializeData="messages.svclog" />
              </listeners>
          </source>
        </sources>
    </system.diagnostics>
    
    
    
      <system.serviceModel>
      
        <diagnostics>
        <messageLogging
             logEntireMessage="true"
             logMalformedMessages="true"
             logMessagesAtServiceLevel="true"
             logMessagesAtTransportLevel="true"
             maxMessagesToLog="3000"
             maxSizeOfMessageToLog="2000"/>
      </diagnostics>

    For more information, please try to refer to:
    http://msdn.microsoft.com/en-us/library/ms732023.aspx.

    Then the Trace viewer will tell you the cause.

    Here is the similar thread: http://stackoverflow.com/questions/12198793/the-remote-server-returned-an-error-404-not-found-wcf-web-exception .

    Hope it can help you.

    Best Regards,
    Amy Peng 

    Wednesday, June 5, 2013 5:11 AM