开发者

WCF: Controlling service endpoint name in self-hosted service

开发者 https://www.devze.com 2023-02-01 03:12 出处:网络
I have a WCF service that\'s hosted in a Windows service. This service needs to run on one of the user\'s machines, and it will be accessed by 开发者_开发问答a client application residing on a differe

I have a WCF service that's hosted in a Windows service. This service needs to run on one of the user's machines, and it will be accessed by 开发者_开发问答a client application residing on a different machine. The service will be exposed over a BasicHttpBinding. The server will be implemented in C# using .NET 4.0. The client will be implemented using .NET 3.5 (external requirements).

I have done a few tweaks of the service in order to squeeze the entire WSDL into a single file (rather than multiple XSDs). The procedure to do this is outlined e.g. here .

I expose the service over a "localhost" endpoint, i.e.:

ServiceHost serviceHost = new ServiceHost(serviceInstance, "http://localhost:8080/...");

Its endpoints are exposed as URIs, relative to the above base address.

My problem is that when generating a proxy using VS2010's Add Service Reference, I get a proxy whose default ctor connects to an "http://localhost:8080/..." endpoint. This works fine if the service is hosted on the same machine as the client (during testing, for instance), but obviously fails when the server and client machines are separate: the client machine has no endpoint listening on "http://localhost:8080/...".

The WSDL file contains:

<wsdl:service name="MyService">
    <wsdl:port name="BasicHttpBinding_IMyService" binding="tns:BasicHttpBinding_IMyService">
        <soap:address location="http://localhost:8080/MyService/IMyService" />

Granted, I could use a different ctor that receives the real hostname to connect to, but given that I generated the client using the host's real address, I kind of expected the client to automatically connect to this endpoint.

I saw on several forums that instead of using localhost on the server I could use its hostname or IP. However, the host may have multiple hostnames and/or IPs, and the service would not know which to choose.

Is there a way to get the auto-generated proxy to use the "real" server's address (as indicated in the WSDL's URL which was used to create the proxy)?


Can't you specify in App.config, <system.serviceModel> section? Maybe you can override the endpoint address, but you can definitely override the meta address.

0

精彩评论

暂无评论...
验证码 换一张
取 消