Hi I am developing wcf application and i am trying to run it locally. I am developing simple application to update some data in database. Below is my code.
[ServiceContract]
public interface IOpportunity
{
[OperationContract]
bool updateOpportunity(opportunityActivity obj);
}
[DataContract]
public class opportunityActivity
{
[DataMember]
public string opportunityID { get; set; }
[DataMember]
public string opportunityStatus { get; set; }
[DataMember]
public string opportunityserviceType { get; set; }
}
public class Opportunity : IOpportunity
{
public bool updateOpportunity(opportunityActivity obj)
{
Test_ROLSP_DB_V1Entities dbobject = new Test_ROLSP_DB_V1Entities();
bool isexists = (from c in dbobject.OpportunityActivityDetails where c.RSOpportunityID == obj.opportunityID select c).Any();
if(isexists)
{
using (var db = new Test_ROLSP_DB_V1Entities())
{
OpportunityActivityDetail oppObject =(from c in db.OpportunityActivityDetails where c.RSOpportunityID==obj.opportunityID select c).FirstOrDefault();
oppObject.DateModified = DateTime.Now;
oppObject.ActivityStatus = obj.opportunityStatus;
oppObject.ServiceType = obj.opportunityserviceType;
int isupdated=db.SaveChanges();
if(isupdated==1)
{
return true;
}
else
{
return false;
}
}
}
else
{
return false;
}
}
}
I can run above solution without any error. Below is the web.config code.
<services>
<service name="RayaSoapService.Opportunity">
<endpoint address="" contract="RayaSoapService.IOpportunity" binding="basicHttpBinding"/>
<endpoint address="mex" contract="IMetadataExchange" binding="mexHttpBinding"/>
</service>
</services>
When i run the above code i get directory listings
When i click on opportunity.svc i get the below error. The type 'RayaSoapService.Service1', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
I am new to WCF. May i know why above error occurs? May i know am i following right way to run the above application? Any help would be appreciated. Thank you.
When you create a WCF service application, Service1.svc creates automatically. If you change name of this file, the name Service1 remains in svc file. Open Opportunity.svc with Notepad and change Service1 to Opportunity.
<%@ ServiceHost Language="C#" Debug="true" Service="Service1" CodeBehind="Opportunity.svc.cs" %>
This is a .NET bug.
change naming in Your opportunity.svc file path
<%@ ServiceHost Language="C#" Debug="true" Service="RayaSoapService.Opportunity" CodeBehind="Opportunity.svc.cs" %>
There is bit more naming to do, if you change default name in WCF service
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.