我正在将WCF服务作为Windows服务进行托管。
下面是一个快照。
myHost = new ServiceHost(typeof(AnalyticsService));
Uri address = new Uri("http://localhost:8080/MathServiceLibrary");
WSHttpBinding binding = new WSHttpBinding();
binding.MaxReceivedMessageSize = 2147483647;
binding.MaxBufferPoolSize = 2147483647;
//binding.Security.Mode = SecurityMode.None;
Type contract = typeof(IAnalyticsService);
myHost.AddServiceEndpoint(contract,binding,address);正如您所看到的,我以前只在本地公开了该服务。我想添加另一个ServiceEndpoint,以便网络上的其他计算机也可以调用该服务。
我假设我需要在上面的代码中添加类似这样的内容:
myHost = new ServiceHost(typeof(AnalyticsService));
Uri address = new Uri("http://localhost:8080/MathServiceLibrary");
Uri new address = new Uri("http://xxx.xxx.xxx:8080/MathServiceLibrary");
WSHttpBinding binding = new WSHttpBinding();
binding.MaxReceivedMessageSize = 2147483647;
binding.MaxBufferPoolSize = 2147483647;
Type contract = typeof(IAnalyticsService);
myHost.AddServiceEndpoint(contract, binding, address);
myHost.AddServiceEndpoint(contract, binding, newaddress);现在,我当前的服务库应用程序配置如下:
<system.serviceModel>
<services>
<service behaviorConfiguration="ServiceLibrary.Service1Behavior"
name="ServiceLibrary.AnalyticsService">
<endpoint address="" binding="wsHttpBinding" contract="ServiceLibrary.IAnalyticsService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8731/Design_Time_Addresses/ServiceLibrary/Service1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceLibrary.Service1Behavior">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>而我在服务库主机中的app.config是
<system.serviceModel>
<services>
<service name="ServiceLibrary.AnalyticsService"
behaviorConfiguration ="MathServiceMEXBehavior">
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/MathService"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MathServiceMEXBehavior">
<serviceMetadata httpGetEnabled="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>我假设我需要使用外部(非本地主机)地址向服务库文件添加另一个基地址。我不知道该在服务库文件中修改什么。
发布于 2010-07-23 02:28:48
不,您不能添加第二个基于http的基地址-每个协议只能选择一个-一个用于http,一个用于net.tcp,依此类推。
您需要做的是在您的app.config中为您的服务主机应用程序创建第二个端点(服务库中的app.config将永远不会被使用-忘记该文件),并为其分配一个完全限定的地址。
<system.serviceModel>
<services>
<service name="ServiceLibrary.AnalyticsService"
behaviorConfiguration ="MathServiceMEXBehavior">
<endpoint name="firstEndpoint"
address=""
binding="wsHttpBinding"
contract="IAnalyticsService" />
<endpoint name="secondEndpoint"
address="http://xxx.xxx.xxx:8080/MathServiceLibrary"
binding="wsHttpBinding"
contract="IAnalyticsService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/MathService"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>因此firstEndpoint将使用基地址,您将能够在
http://localhost:8080/MathService而secondEndpoint使用一个特定的、完全限定的URL,您可以在
http://xxx.xxx.xxx:8080/MathServiceLibrary但是:为什么要有第二个端点呢?如果你想公开不同的协议,你通常只有第二个端点,例如,你通常会有一个http,一个https,一个net.tcp端点等等。有两个单独的http端点具有相同的合同和相同的绑定,这对我来说没有多大意义。
https://stackoverflow.com/questions/3312011
复制相似问题