2009-07-07 7 views
3

app.configファイル内のMEXエンドポイントでエンドポイントを定義する方法と、アプリケーションを実行するために必要なものIXMLServiceというサービス契約が1つあり、WsHttpBindingを使用しています。 私に例を挙げてください。 app.configを作成したら、サービスを開始するにはどうすればいいですか?app.configファイルでエンドポイントを定義する方法は?

答えて

6
<system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
      <behavior name="MetadataBehavior"> 
       <serviceMetadata httpGetEnabled="true" /> 
      </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <services> 
     <service name="YourNamespace.XMLService" behaviorConfiguration="MetadataBehavior"> 

      <!-- Use the host element only if your service is self-hosted (not using IIS) --> 
      <host> 
       <baseAddresses> 
        <add baseAddress="http://localhost:8000/service"/> 
       </baseAddresses> 
      </host> 

      <endpoint address="" 
         binding="wsHttpBinding" 
         contract="YourNamespace.IXMLService"/> 

      <endpoint address="mex" 
         binding="mexHttpBinding" 
         contract="IMetadataExchange"/> 
     </service> 
    </services> 
</system.serviceModel> 

UPDATE:

class Program 
{ 
    static void Main(string[] args) 
    { 
     using (var host = new System.ServiceModel.ServiceHost(typeof(XMLService))) 
     { 
      host.Open(); 
      Console.WriteLine("Service started. Press Enter to stop"); 
      Console.ReadLine(); 
     } 
    } 
} 
+0

これはおそらく勝ちました仕事はしません - MEXエンドポイントに完全な完全なアドレスがなく、 "baseAddresses"が定義されていません...... –

+1

@marc_s、あなたは正しい、私はIISとみなしました。私はそれに応じて自分の投稿を修正した。 –

+0

thanxダーリン、このapp.configファイルを作成した後、私は何か他のことをする必要がありますか、実際にapp.configファイルを作成してクライアントを作成しましたが、このアドレスにエンドポイントがないと言います... –

2

ダーリンの答えはそこほとんどです:あなたは(以前はapp.configを追加することによって)、それをホストするために、次のコンソールアプリケーションを書くことができ、サービスを開始するには - サービスとmexエンドポイントの両方に完全な完全アドレスを指定するか、ベースアドレスを追加する必要があります。

<system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
      <behavior name="MetadataBehavior"> 
       <serviceMetadata httpGetEnabled="true" /> 
      </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <services> 
     <service name="XMLService" behaviorConfiguration="MetadataBehavior"> 
      <host> 
      <baseAddresses> 
       <add baseAddress="http://localhost:8888/"/> 
      </baseAddresses> 
      </host> 
      <endpoint address="MyService" 
         binding="wsHttpBinding" 
         contract="IXMLService"/> 

      <endpoint address="mex" 
         binding="mexHttpBinding" 
         contract="IMetadataExchange"/> 
     </service> 
    </services> 
</system.serviceModel> 

あなたのサービスをご希望の場合、あなたはまた、エンドポイントに直接の完全なアドレスを指定することができますhttp://localhost:8888/mex

http://localhost:8888/MyService、そしてあなたのMEXデータに次のようになります。

 <service name="XMLService" behaviorConfiguration="MetadataBehavior"> 
      <endpoint address="http://localhost:8888/MyService" 
         binding="wsHttpBinding" 
         contract="IXMLService"/> 

      <endpoint address="http://localhost:8888/MyService/mex" 
         binding="mexHttpBinding" 
         contract="IMetadataExchange"/> 
     </service> 

マルク・

関連する問題