无法在localhost中运行wcf服务

问题描述:

嗨,我正在开发wcf应用程序,我试图在本地运行它。我开发简单的应用程序来更新数据库中的一些数据。以下是我的代码。无法在localhost中运行wcf服务

[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; 
     } 
    } 
} 

我可以在没有任何错误的情况下运行以上解决方案。以下是web.config代码。

<services> 
    <service name="RayaSoapService.Opportunity"> 
    <endpoint address="" contract="RayaSoapService.IOpportunity" binding="basicHttpBinding"/> 
    <endpoint address="mex" contract="IMetadataExchange" binding="mexHttpBinding"/> 
    </service> 
</services> 

当我运行上面的代码,我得到的目录列表 enter image description here

当我opportunity.svc点击我得到下面的错误。 找不到类型'RayaSoapService.Service1',作为ServiceHost指令中的Service属性值提供,或者在配置元素system.serviceModel/serviceHostingEnvironment/serviceActivations中提供。

我是WCF新手。我可否知道为什么会出现上述错误?我可否知道我是否按照正确的方式运行上述应用程序?任何帮助,将不胜感激。谢谢。

+0

https://docs.microsoft.com/en -us/dotnet/framework/wcf/how-to-host-a-wcf-service-in-a-managed-application – Hybridzz

+0

http://code-zest.blogspot.sg/2013/10/different-ways-to -run-wcf-services.html – Hybridzz

当您创建一个WCF服务应用程序时,Service1.svc会自动创建。如果您更改此文件的名称,名称Service1仍保留在svc文件中。用记事本打开Opportunity.svc并将Service1更改为机会。

<%@ ServiceHost Language="C#" Debug="true" Service="Service1" CodeBehind="Opportunity.svc.cs" %> 

这是一个.NET错误。

+0

正确我自己修复了它。谢谢.. –

+0

我可以知道如何为上述服务提供xml输入吗? –

改变你opportunity.svc文件路径命名

<%@ ServiceHost Language="C#" Debug="true" Service="RayaSoapService.Opportunity" CodeBehind="Opportunity.svc.cs" %> 

还有更多位的命名做,如果你在WCF服务更改默认名称