Click here to Skip to main content
15,885,954 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, 

I have created the Two Methods one is to Get and Another one is to Create,

For Getting the Data is working fine , but when i trying to post the Data is showing the Error like " Method not Found(404)"

The Code is as following.

Contract Methods :


C#
public interface IContactPositionService    {
[OperationContract]
[WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, Method = "GET", RequestFormat=WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetContactPositionList")]
List<ContactPosition> GetContactPositionList();
[OperationContract]
[WebInvoke(Method = "PUT", BodyStyle = webMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "AddContactPosition")]
int AddContactPosition(ContactPosition position);}


And Corresponding Serivice class is like :

C#
public class ContactPositionService : IContactPositionService
   {
 public List<ContactPosition> GetContactPositionList()
       {
           DataSet ds = clsObj.GetContactPositionsList();
           return ConverterHelper.Convert<ContactPosition>(ds.Tables[0]);
       }

public int AddContactPosition(ContactPosition position)
       {
         //  throw new System.NotImplementedException();
       }


And in Web.config file i have configured the End Points As :

XML
<services>
      <service name="VirtusMobileService.ContactPositionService" behaviorConfiguration="VMS.Position.ServiceBehaviour">
        <endpoint address="" behaviorConfiguration="VMS.Position.EndPointBehaviour"
          binding="webHttpBinding" bindingConfiguration="" name="VMS.Position.EndPoint"
          contract="VirtusMobileService.IContactPositionService" />
        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="VMS.Position.EndPointBehaviour">
          <webHttp helpEnabled="true" />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="VMS.ServiceBehaviour">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
        <behavior name="VMS.Position.ServiceBehaviour">
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>


From the Client Asp.net page we call the Services for adding the Contact person object as like below :

C#
<pre lang="c#">
private void AddData()
        {
            string sURL = "http://localhost:51293/ContactPositionService.svc/AddContactPosition";       
            ContactPosition order = new ContactPosition
            {
                PositionCode="10550",
                PositionFinbaseId=11,
                PositionTitle="Manager"
            };

            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(ContactPosition));
            MemoryStream mem = new MemoryStream();
            ser.WriteObject(mem, order);
            string data = Encoding.UTF8.GetString(mem.ToArray(), 0, (int)mem.Length);
            WebClient webClient = new WebClient();
            webClient.Headers["Content-type"] = "application/json";
            webClient.Encoding = Encoding.UTF8;
            webClient.UploadData(sURL, "PUT", mem.ToArray());         // Here it is showing Error
             Console.WriteLine("Order placed successfully...");  

}


While it comes to , " uploadData " it is showing error like  "  remote server returned an error: (404) Not Found."

   If i am trying to Get the Data using the   "GetContactPositionList" it showing the data Correctly , but when i am trying to work with "PUT" method it is showing that error.

I tested the url in Fiddler , it is showing the same error in Response Header "HTTP/1.1 405 Method Not Allowed" and in text viewer it showing like below


HTML
<div id="content">
      <p class="heading1">Service</p>
      <p xmlns="">Method not allowed. Please see the <a rel="help-page" href="http://localhost:51293/ContactPositionService.svc/help">service help page</a> for constructing valid requests to the service.</p>
    </div>


Please Suggest the answer.

Thanks.
Posted
Comments
V G S Naidu A 23-Apr-14 0:47am    
please suggest me the valuable solution for this

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900