2012-06-16 19 views
0

我用這個MSDN例子來構建我的控制檯主機的應用程序:自託管WCF合同未發現

http://msdn.microsoft.com/en-us/library/ms731758.aspx

它的工作原理我有一個服務運行,同時運行,我可以將其添加爲服務引用到我的Silverlight類庫ViewModel和我可以看到它在瀏覽器中運行。

然而,當我運行Silverlight應用程序,我得到了以下錯誤消息:

找不到引用合同 「ServiceLayer.IServiceLayer」在ServiceModel客戶端配置 欄目默認終結點元素。這可能是因爲沒有爲您的應用程序找到配置文件 ,或者因爲在客戶端元素中找不到與此 合同匹配的端點元素。

這是我的服務代碼:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.ServiceModel; 
using System.ServiceModel.Activation; 
using Model; 

namespace ServiceLayer 
{ 
    [ServiceContract(Namespace = "ServiceLayer")] //This has to match references or updating the service reference will not work. 
    public interface IServiceLayer 
    { 
     [OperationContract] //This is needed for each method. 
     string Compile(string cscode, string name, string type, int token); 

     [OperationContract] //This is needed for each method. 
     string LoginClick(string username, string password, bool createuser, int token); 

     [OperationContract] 
     bool IsLoggedIn(int token); 

     [OperationContract] //This is needed for each method. 
     object[] GetMessages(int token); 

     [OperationContract] //This is needed for each method. 
     int GetToken(int token); 

     [OperationContract] //This is needed for each method. 
     string[][] GetPlugins(int token); 

     [OperationContract] //This is needed for each method. 
     string Finalize(int token, string[] descriptions); 

     [OperationContract] //This is needed for each method. 
     object[][] Communicate(string methodName, int token, object[] args); 
    } 

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
    public class ServiceLayer : IServiceLayer 
    { 
     public string Compile(string cscode, string name, string type, int token) 
     { 
      // Add your operation implementation here 
      ModelInterface MI = new ModelInterface(); 
      return MI.Compile(cscode, name, type, token); 
     } 

     public String LoginClick(string username, string password, bool createuser, int token) 
     { 
      ModelInterface MI = new ModelInterface(); 
      return MI.LoginClick(username, password, createuser, token); 
     } 

     public bool IsLoggedIn(int token) 
     { 
      ModelInterface MI = new ModelInterface(); 
      return MI.IsLoggedIn(token); 
     } 

     public object[] GetMessages(int token) 
     { 
      ModelInterface MI = new ModelInterface(); 
      return MI.GetMessages(token); 
     } 

     public int GetToken(int token) 
     { 
      ModelInterface MI = new ModelInterface(); 
      return MI.GetToken(token); 
     } 

     public string[][] GetPlugins(int token) 
     { 
      ModelInterface MI = new ModelInterface(); 
      return MI.GetPlugins(token); 
     } 

     public string Finalize(int token, string[] descriptions) 
     { 
      ModelInterface MI = new ModelInterface(); 
      return MI.Finalize(token, descriptions); 
     } 

     public object[][] Communicate(string methodName, int token, object[] args) 
     { 
      ModelInterface MI = new ModelInterface(); 
      return MI.Communicate(methodName, token, args); 
     } 
     // Add more operations here and mark them with [OperationContract] 
    } 
} 

這是視圖模型的ServiceReferences.ClientConfig:

<configuration> 
<system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
      <binding name="BasicHttpBinding_IServiceLayer" maxBufferSize="2147483647" 
       maxReceivedMessageSize="2147483647"> 
       <security mode="None" /> 
      </binding> 
      <binding name="BasicHttpBinding_IServiceLayer1" maxBufferSize="2147483647" 
       maxReceivedMessageSize="2147483647"> 
       <security mode="None" /> 
      </binding> 
     </basicHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost:3263/front" binding="basicHttpBinding" 
      bindingConfiguration="BasicHttpBinding_IServiceLayer" contract="IServiceLayer" 
      name="BasicHttpBinding_IServiceLayer" /> 
     <endpoint address="http://localhost:3263/front" binding="basicHttpBinding" 
      bindingConfiguration="BasicHttpBinding_IServiceLayer1" contract="ServiceLayer.IServiceLayer" 
      name="BasicHttpBinding_IServiceLayer1" /> 
    </client> 
</system.serviceModel> 

這是的Web.Config文件項目與託管Silverlight應用程序的網站。 我張貼,因爲我想這Could not find default endpoint element 指南 - 即複製從虛擬機配置的servicemodel部分下面也web.config中:沒有ASP.NET儘管我付出的事實

<configuration> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0"/> 
    <pages controlRenderingCompatibilityVersion="4.0"/> 
    </system.web> 
    <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name=""> 
      <serviceMetadata httpGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <bindings> 
     <customBinding> 
     <binding name="OrgOS.Web.ServerCommunicationService.customBinding0"> 
      <binaryMessageEncoding/> 
      <httpTransport/> 
     </binding> 
     <binding name="OrgOS.Web.ServiceLayer.customBinding0"> 
      <binaryMessageEncoding/> 
      <httpTransport/> 
     </binding> 
     </customBinding> 
    </bindings> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/> 
    <services> 
     <service name="OrgOS.Web.ServiceLayer"> 
     <endpoint address="" binding="customBinding" bindingConfiguration="OrgOS.Web.ServiceLayer.customBinding0" contract="OrgOS.Web.ServiceLayer"/> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
     </service> 
    </services> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
</configuration> 

我的服務器我租來了因爲它支持休假,我有最後期限! 試圖讓WCF的工作是推動我瘋了 - 請幫我...

爲什麼這麼嚇壞很難展示一個簡單的Silverlight項目...

回答

0

啊沒關係;您必須在View Silverlight項目,Web項目和ViewModel Silverlight項目中發佈配置設置。

您還必須刪除所有端點和綁定,但必須刪除所有端點和綁定,以免造成混淆。

還改變了一些東西以確保namespace =「namespace」符合實際的命名空間。

...不是因爲這個原因,所以我得到的東西都是無效的結果。

FML現在。