未找到自托管WCF合同

时间:2012-06-16 21:49:03

标签: wcf silverlight sql-server-2008 hosting

我使用此MSDN示例构建我的控制台主机应用程序:

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

它有效我运行了一个服务,在运行时我可以将它作为服务引用添加到我的Silverlight类库ViewModel中,我可以看到它在浏览器中运行。

但是当我运行Silverlight应用程序时,我收到以下错误消息:

  

找不到引用合同的默认端点元素   ServiceModel客户端配置中的“ServiceLayer.IServiceLayer”   部分。这可能是因为找不到配置文件   您的应用程序,或者没有匹配此的端点元素   合同可以在客户要素中找到。

这是我的服务代码:

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]
    }
}

这是ViewModel的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部分从VM配置复制到web.Config下面:

<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>

我租用的服务器没有ASP.NET,尽管我付了钱,支持是休假,我有最后期限! 试图让WCF工作让我很生气 - 请帮助我...

为什么要显示一个简单的Silverlight项目真是太难了......

1 个答案:

答案 0 :(得分:0)

啊,没关系;您必须在View Silverlight项目,Web项目和ViewModel Silverlight项目中发布配置设置。

您还必须删除所有端点和绑定,但必须删除一个端点和绑定。

还改变了一些东西以确保namespace =“namespace”符合实际的命名空间。

......不是因为那个原因,所以我得到的结果是无效的结果。

现在是FML。