我是WCF的新手。我有一个正常的三维项目的asp.net项目。我的解决方案的结构类似于 1. DAL(类库数据访问层项目) 2. BL(类库业务逻辑) 3. BO(业务对象类库) 4. TestOnline(主Web项目客户端) 5. WCFServices(类库项目) 现在我想包括WCF类库项目到相同的解决方案,并使用WCF服务学习。我创造了适当的服务和合同。主Web项目我的web.config文件的修改如下如何配置我的asp.net项目以使用WCF服务
<configuration>
<connectionStrings>
<add name="dbConnect" connectionString="Data Source=WIN-3150RFE75I8\PMSSERVER;Initial Catalog=TestDb_OnlineExam;Persist Security Info=True;User ID=sa;Password=pmsadmin1!" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Forms">
</authentication>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"></serviceHostingEnvironment>
<services>
<service name="WCFServices.LoginWcfService" behaviorConfiguration="LoginWcfServiceBehavior">
<endpoint address="" binding="webHttpBinding" contract="WCFServices.ILoginWcfService" behaviorConfiguration="web">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="LoginWcfServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceDiscovery></serviceDiscovery>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="webHttpBinding" scheme="http"/>
</protocolMapping>
</system.serviceModel>
</configuration>
当我尝试运行我的项目显示错误消息是:
找不到引用合同“LoginServiceReference默认终结点元素。 ILMinWcfService'在ServiceModel客户端配置部分。这可能是因为没有找到适用于您的应用程序的配置文件,或者因为在客户端元素中找不到匹配此合同的端点元素。
我无法找出有关此错误的任何信息。
我检查运行我的WCF服务,它运行良好。只是不能在我的web项目中使用它。我需要添加/修改哪些属性才能使其正常工作。
那是正确的,你有一个包含WCF项目和ASP.Net项目,DAL,业务层项目沿着单一的Visual Studio解决方案?如果是这样,我想我会做的第一件事是保持WCF项目包括所有从属项目成为一个严格的VS解决方案。通过这种方式,您可以将WCF托管在基于控制台的应用程序中进行调试。其次,你的配置文件没有任何“LoginServiceReference.ILoginWcfService”的合同条目你有没有发布web.config文件的所有内容? –
@YawarMurtaza没有必要把所有的WCF项目放在_“另一个解决方案”中 - 仅用于基于控制台的调试或其他方式 – MickyD
@MickyD这就是正确的,我从来没有说过它是必要的。由于OP对于WCF来说是新的,因此保持安全并有助于组织和透明是有意义的。像这样的东西真的帮助学习新的tehcnologies :) –