wcf端点相对地址
我刚刚学习wcf,无法理解一件非常基本的事情。
我正在创建一个 WCF 服务,我希望将其托管在 IIS 中,就像 Web 应用程序一样,它有自己的路径,如 http://myhost/myapp/
等。
我正在 VS 中创建 WCF 服务项目,我有一个描述它的 *.svc
文件,然后我定义一个简单的端点,如下所示:
<endpoint address=""
binding="basicHttpBinding"
contract="wcf_service_auth.IPshService" />
然后我像 IIS Web 一样发布此服务将应用程序添加到虚拟目录,假设它的名称为 psh_pub
,这样我就可以通过 URL http://localhost/psh_pub/pshservice.svc/
访问该服务。它向我显示了 WCF 问候页面,并为我提供了 WSDL 的链接,这为我提供了正确的 wsdl 描述。
没关系。
下一步 - 我想添加 MEX 端点。我添加到配置:
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
也没关系,可以通过地址 http://localhost/psh_pub/pshservice.svc/mex
访问端点,并且 WcfTestClient.exe
为我提供了正确的配置从那个网址。
问题来了。
我有一项在 IIS 下工作的 WCF 服务,我想向其添加一个端点。例如,让它成为一个 net.tcp
端点。 IIS 默认配置为接受端口 808 上的 net.tcp
连接,我正在将 net.tcp
协议添加到我的 Web 应用程序的属性中,并且我想添加我的服务的端点如下:
<endpoint address=""
binding="netTcpBinding"
contract="wcf_service_auth.IPshService" />
现在我假设我的服务应该可以通过 url net.tcp://localhost:808/psh_pub/pshservice.svc
访问。但事实并非如此。网络上的每个“操作方法”和手册都告诉我应该在配置文件中指定完整地址,如下所示:
<endpoint address="net.tcp://localhost:808/psh_pub/pshservice.svc"
binding="netTcpBinding"
contract="wcf_service_auth.IPshService" />
如果我这样做,它就可以工作。但如果将服务托管在另一个虚拟目录中,我需要更改配置。如果我将其托管在其他服务器上,我需要更改配置。如果我将其托管在多个服务器上,我将必须维护与我拥有的服务器一样多的配置。
所以主要问题是:
WCF 中是否有任何方法可以指定 IIS 托管的 WCF 服务的 net.tcp
(或 https)端点,而不为其指定绝对 url?
I'm just learning wcf and can't understand one very basic thing.
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.
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" />
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.
That's ok.
The next step - I want to add a MEX endpoint. I add to config:
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
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.
Here the problem comes.
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" />
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.
So the main questions is:
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够为您的
net.tcp
服务端点定义一个基地址:然后您应该能够在实际端点中使用相对地址:
You should be able to define a base address for your
net.tcp
service endpoints:Then you should be able to use relative addresses in your actual endpoints:
WCF 无文件激活 (.Net 4.0) 将允许您使用relativeAddress 属性在相对虚拟路径下注册:
此链接讨论了它: http:// msdn.microsoft.com/en-us/library/ee354381.aspx
WCF file-less activation (.Net 4.0) will let you register under a relative virtual path using the relativeAddress attribute:
This link talks about it: http://msdn.microsoft.com/en-us/library/ee354381.aspx