wcf端点相对地址 [英] wcf endpoint relative address
问题描述
我只是在学习wcf,无法理解一件非常基本的事情.
I'm just learning wcf and can't understand one very basic thing.
我正在创建WCF服务,我希望将其托管在IIS中,就像Web应用程序一样,它具有自己的路径,如http://myhost/myapp/
和其他所有内容.
I'm creating a WCF service which I want to be hosted in IIS just like web application with it's own path like http://myhost/myapp/
and everything.
我正在VS中创建WCF服务项目,我已经得到一个描述它的*.svc
文件,然后像这样定义了一个简单的端点:
I'm creating the WCF service project in VS, I've got an *.svc
file describing it, then I define a simple endpoint to it like that:
<endpoint address=""
binding="basicHttpBinding"
contract="wcf_service_auth.IPshService" />
然后,将该服务像IIS Web应用程序一样发布到虚拟目录,假设它的名称为psh_pub
,那么我可以通过URL http://localhost/psh_pub/pshservice.svc/
访问该服务.它显示了WCF问候页面,并提供了到WSDL的链接,从而为我提供了正确的wsdl描述.
Then I publish this service like an IIS web application to a virtual directory, let's assume it's name psh_pub
, so I can access the service via url http://localhost/psh_pub/pshservice.svc/
. It shows me WCF greetings page and gives me a link to WSDL, which gives me correct wsdl description.
没关系.
下一步-我想添加一个MEX端点.我添加到配置:
The next step - I want to add a MEX endpoint. I add to config:
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
也可以,可以在地址http://localhost/psh_pub/pshservice.svc/mex
上访问端点,并且WcfTestClient.exe
从该URL给我正确的配置.
That's ok too, the endpoint is accessible at address http://localhost/psh_pub/pshservice.svc/mex
and WcfTestClient.exe
gives me correct config from that url.
问题来了.
我有一个在IIS下工作的WCF服务,我想向它添加一个终结点.例如,将其设为net.tcp
端点.默认情况下,IIS已配置为在端口808处接受net.tcp
连接,并且我将net.tcp
协议添加到Web应用程序的属性中,并且我想向服务中添加一个端点,如下所示:
I have a WCF service working under IIS and I want to add one more endpoint to it. For example let it be a net.tcp
endpoint. The IIS is configured by default to accept net.tcp
connections at port 808 and I'm adding net.tcp
protocol to properties of my web app, and I want to add an endpoint to my service like that:
<endpoint address=""
binding="netTcpBinding"
contract="wcf_service_auth.IPshService" />
,现在我假设应该可以通过URL net.tcp://localhost:808/psh_pub/pshservice.svc
访问我的服务.但事实并非如此.网络上的每本操作方法"和手册都告诉我,我应该在配置文件中指定完整的地址,如下所示:
and now I assume that my service should be accessible via the url net.tcp://localhost:808/psh_pub/pshservice.svc
. But it's not. And every "how-to" and manual on the web tells that I should specify full address in the config file like that:
<endpoint address="net.tcp://localhost:808/psh_pub/pshservice.svc"
binding="netTcpBinding"
contract="wcf_service_auth.IPshService" />
如果我这样做,它会起作用.但是,如果将服务托管在另一个虚拟目录中,则需要更改配置.如果将其托管在其他服务器上,则需要更改配置.如果将其托管在多台服务器上,则必须维护与我拥有的服务器一样多的配置.
And if I do so, it works. But if host the service in another virtual directory, I'll need to change the config. If I host it on the other server, I'll need to change config. If I host it on multiple servers, I'll have to maintain as many configs as servers I have.
所以主要问题是:
WCF中是否有任何方法可以指定IIS托管的WCF服务的net.tcp
(或https)终结点,而无需为其指定绝对URL?
Is there any way in WCF to specify a net.tcp
(or https) endpoint of a IIS-hosted WCF service without specifying absolute url for it?
推荐答案
您应该能够为net.tcp
服务端点定义基本地址:
You should be able to define a base address for your net.tcp
service endpoints:
<service name="YourServiceName">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:808/psh_pub/" />
</baseAddresses>
</host>
然后,您应该可以在实际端点中使用相对地址:
Then you should be able to use relative addresses in your actual endpoints:
<endpoint name="Tcp01"
address="pshservice.svc"
binding="netTcpBinding"
contract="wcf_service_auth.IPshService" />
</service>
这篇关于wcf端点相对地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!