无法在localhost中运行wcf服务

时间:2017-08-02 07:40:04

标签: c# wcf

您好我正在开发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时,我得到以下错误。 在ServiceHost指令中作为Service属性值提供的类型&#39; RayaSoapService.Service1&#39;或在配置元素system.serviceModel / serviceHostingEnvironment / serviceActivations中提供的类型无法找到。

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

2 个答案:

答案 0 :(得分:1)

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

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

这是一个.NET错误。

答案 1 :(得分:0)

更改您的opportunity.svc文件路径中的命名

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

如果您在WCF服务中更改默认名称

,还有更多命名要做
相关问题