简体   繁体   English

为WCF服务使用IP地址

[英]Using an IP address for a WCF Service

I have a C# app that calls my WCF on my server. 我有一个C#应用程序,可在服务器上调用WCF。

At some time I will want to move part of my uploading process from client to server to a different server. 有时我会希望将部分上传过程从客户端转移到服务器,再转移到其他服务器。

So, this is what I was going to do. 所以,这就是我要做的。

My desktop application invokes a WCF hosted on my server using the full DNS name ~ www.mysite.com. 我的桌面应用程序使用完整的DNS名称〜www.mysite.com调用服务器上托管的WCF。

That [web method] will then return an IP address to the client. 然后,该[web方法]将IP地址返回给客户端。

The client will then upload images to a DIFFERENT server that is accessible only by an IP address. 然后,客户端会将图像上传到仅可通过IP地址访问的其他服务器。

The idea is that if my app is successful and I would need to 'load-balance' the image uploads I would then have a mechanism to specify different destination servers to my clients. 这个想法是,如果我的应用程序成功,并且我需要“负载均衡”图像上传,那么我将拥有一种机制来为客户端指定不同的目标服务器。

So, I started looking in StackOverFlow for a way to dynamically set the IP address/End-Point of my WCF. 因此,我开始在StackOverFlow中寻找一种动态设置WCF的IP地址/端点的方法。 This was easy to do for web services but it seems to me a bit more difficult for WCF. 对于Web服务,这很容易做到,但对我而言,对于WCF来说似乎有点困难。

Needless to say I was about to go through the answers here but came across a comment saying that the WCF needs to be using DNS. 毋庸置疑,我将在此处浏览答案,但遇到评论说WCF需要使用DNS。

Is this true? 这是真的?

As this is the only server I got and it is using DNS (I have not got access to a secondary server yet) I cannot test this out. 由于这是我获得的唯一服务器,并且正在使用DNS(我尚未访问辅助服务器),因此无法进行测试。

Are both things possible? 两者都有可能吗?

When you write a web service client, you can change the server endpoint programmatically. 编写Web服务客户端时,可以以编程方式更改服务器端点。 It has nothing to do with using WCF or not in the server. 它与是否在服务器中使用WCF无关。

MyClient client = new MyService.MyClient();
client.Endpoint.Address = new EndpointAddress(new Uri("target URL"));
client.Open();

You could find more details on the EndPointAddress MSDN reference . 您可以在EndPointAddress MSDN参考上找到更多详细信息。

Hope I helped! 希望我能帮上忙!

MyClient client = new MyService.MyClient();
client.Endpoint.Address = new EndpointAddress(new Uri("target URL"));
client.Open();

It works, we could also use 它有效,我们也可以使用

myService.MyClient client = new myService.MyClient ();
 //enter code here, when the service is created as wcf application

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM