Note that there are some explanatory texts on larger screens.

plurals
  1. POWCF: Controlling service endpoint name in self-hosted service
    text
    copied!<p>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).</p> <p>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. <a href="http://weblogs.asp.net/pglavich/archive/2010/03/16/making-wcf-output-a-single-wsdl-file-for-interop-purposes.aspx" rel="nofollow">here</a> .</p> <p>I expose the service over a "localhost" endpoint, i.e.:</p> <pre><code>ServiceHost serviceHost = new ServiceHost(serviceInstance, "http://localhost:8080/..."); </code></pre> <p>Its endpoints are exposed as URIs, relative to the above base address.</p> <p>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/...". </p> <p>The WSDL file contains:</p> <pre><code>&lt;wsdl:service name="MyService"&gt; &lt;wsdl:port name="BasicHttpBinding_IMyService" binding="tns:BasicHttpBinding_IMyService"&gt; &lt;soap:address location="http://localhost:8080/MyService/IMyService" /&gt; </code></pre> <p>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.</p> <p>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.</p> <p>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)?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload