我是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 :) –