0

我使用这个 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 应用程序的网站。我发布它是因为我尝试了这个找不到默认端点元素 指南 - 即将 VM 配置中的 servicemodel 部分复制到下面的 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 项目这么难……

4

1 回答 1

0

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

您还必须删除所有端点和绑定,但要避免混淆。

还更改了一些内容以确保 namespace="namespace" 适合实际的命名空间。

......并不是因为这个原因,事情才有效,哦,不,我得到的只是无效的结果。

现在FML。

于 2012-06-16T22:36:30.517 回答