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>

これは、Silverlight アプリをホストする Web サイトを含むプロジェクトの Web.Config ファイルです。これを試したので投稿します デフォルトのエンドポイント要素 ガイドが見つかりませんでした-つまり、サービスモデルセクションを 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 プロジェクトを表示するのが非常に難しいのはなぜですか...

4

1 に答える 1

0

ああ、気にしないでください。View Silverlight プロジェクト、Web プロジェクト、および ViewModel Silverlight プロジェクトの両方に構成設定を投稿する必要があります。

すべてのエンドポイントとバインディングも削除する必要がありますが、混乱を避けるために 1 つです。

また、namespace="namespace" が実際の名前空間に適合するように変更しました。

...その理由でうまくいくわけではありません。無効な結果しか得られません。

現在、FML.

于 2012-06-16T22:36:30.517 に答える