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 :
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 :
public class ContactPositionService : IContactPositionService
{
public List<ContactPosition> GetContactPositionList()
{
DataSet ds = clsObj.GetContactPositionsList();
return ConverterHelper.Convert<ContactPosition>(ds.Tables[0]);
}
public int AddContactPosition(ContactPosition position)
{
}
And in Web.config file i have configured the End Points As :
<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 :
<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());
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
<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.