1

app.config ファイルを変更しようとしています

新しい ServiceEndPoint を削除/追加しようとしています (要件は、エンドポイントのアドレスを変更する機能です)

マイサービス

class SVNServerUIService : ISVNServerUIService
{
    public string SetServerData(int portNumber)
    {
                  var clientSection   = ConfigurationManager.GetSection("system.serviceModel/services") as ServicesSection ;


        var endpoint2 = new ServiceEndpointElement
            (new Uri("http://localhost:64445/SVNServerUIService"),
            "SVNManagementService.ISVNServerUIService");

        //This line is giving Error 

        clientSection.Services["SVNManagementService.SVNServerUIService"].Endpoints.RemoveAt(1); 
        clientSection.Services["SVNManagementService.SVNServerUIService"].Endpoints.Add(endpoint2);
        clientSection.CurrentConfiguration.Save();

        return clientSection.Services["SVNManagementService.SVNServerUIService"].Endpoints[1].Address.ToString();
    }

    public ClientCompositeType GetDataUsingDataContract(ClientCompositeType composite)
    {
        throw new NotImplementedException();
    }
}

App.config

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="basicHttpSecuredBinding">
      <security mode="Transport">
        <message clientCredentialType="Certificate" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<services>      
  <service behaviorConfiguration="behaviorMetadata" name="SVNManagementService.SVNClientUIService">
    <endpoint address="http://localhost:8888/SVNClientService" binding="basicHttpBinding"
      name="basicHttpEndPoint" contract="SVNManagementService.ISVNClientUIService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="net.tcp://localhost:8889/SVNService/mextcp"
      binding="mexTcpBinding" name="mexTcpEndPoint" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8732/Design_Time_Addresses/SVNManagementService/Service1/" />
      </baseAddresses>
    </host>
  </service>

  <service behaviorConfiguration="behaviorMetadata" name="SVNManagementService.SVNServerUIService">
    <endpoint address="http://localhost:9998/SVNServerService" binding="basicHttpBinding"
      name="basicHttpEndPoint" contract="SVNManagementService.ISVNServerUIService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="net.tcp://localhost:9997/SVNService/mextcp"
      binding="mexTcpBinding" name="mexTcpEndPoint" contract="IMetadataExchange" />
    <host>          
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="behaviorMetadata">
      <serviceMetadata httpGetEnabled="false" httpGetUrl="http://localhost:8888/SVNService/metadata"
        httpsGetEnabled="false" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
</system.serviceModel>

app.config でサービスのアドレスを変更して保存するにはどうすればよいですか。

4

0 に答える 0