日期:2014-05-17  浏览次数:21125 次

wcf通过代码怎么不能覆盖端口号设置?
配置文件
<system.serviceModel>
  <bindings />
  <client />
  <behaviors>
  <serviceBehaviors>
  <behavior name="ServiceBehavior">
  <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:8730/DBService/Metadata" />
  <serviceDebug includeExceptionDetailInFaults="true" />
  <serviceThrottling maxConcurrentCalls="1000" maxConcurrentSessions="1000" maxConcurrentInstances="1000" />
  <dataContractSerializer maxItemsInObjectGraph="6553600"/>
  </behavior>
  </serviceBehaviors>
  </behaviors>
  <services>
  <service behaviorConfiguration="ServiceBehavior" name="ABCDE.NetService.Class.DBService">
  <endpoint address="http://localhost:8730/MyService/" binding="basicHttpBinding"
  name="DBService" contract="ABCDE.NetService.Interface.IDBService" >
  </endpoint>
  </service>
  </services>
  </system.serviceModel>

我在代码中想通过用户的设置来改变默认的终结点设置
C# code

string url = string.Format("http://{0}:{1}/DBService/", "192.168.1.100", "1234");
                    Uri baseAddress = new Uri(url);
                    ServiceHost host = new ServiceHost(typeof(DBService), baseAddress);
                    host.AddServiceEndpoint(typeof (IDBService), new BasicHttpBinding(), "");
                    host.Open();


通过以上代码应该是覆盖配置文件的设置,但现实情况是ip地址覆盖,但端口号仍然必须用8730来访问,用新的端口号1234来访问会找不到终结点,这是什么原因呀?

------解决方案--------------------
没有覆盖,而是新增了一个,两个地址都可用,你试试访问那个IP:端口,也存在。