Skip to content

Commit

Permalink
Ensure same default hostname and service path is used (CoreWCF#434)
Browse files Browse the repository at this point in the history
Accepts --hostname cli argument

Co-authored-by: jleyva <[email protected]>
  • Loading branch information
JohnLeyva and jleyva authored Oct 5, 2021
1 parent 62fd7e0 commit f5f3fdc
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/Samples/DesktopClient/DesktopClient.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net472</TargetFramework>
Expand Down
18 changes: 11 additions & 7 deletions src/Samples/DesktopClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@ namespace DesktopClient
{
class Program
{
private static readonly string s_hostname = "localhost";

static void Main()
/// <remarks>
/// use commanline argument localhost
/// or something similar to indicate the WCF Server hostname
/// </remarks>
static void Main(string[] args)
{
Settings settings = new Settings().SetDefaults(s_hostname);
string hostname = args.Length >= 1 ? args[0] : null;

Console.Title = "WCF .Net Framework Client";
Settings settings = ClientLogic.BuildClientSettings(hostname);

void log(string value) => Console.WriteLine(value);
ClientLogic.CallUsingWcf(settings, log);
ClientLogic.InvokeEchoServiceUsingWcf(settings, log);

string rawSoapResponse = ClientLogic.CallUsingWebRequest(settings.basicHttpAddress);
string rawSoapResponse = ClientLogic.InvokeEchoServiceUsingWebRequest(settings.basicHttpAddress);
Console.WriteLine($"Http SOAP Response:\n{rawSoapResponse}");

Console.WriteLine("Hit enter to exit");
Console.ReadLine();
}

}
}
2 changes: 1 addition & 1 deletion src/Samples/DesktopServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private static void LogHostUrls(ServiceHost host)

static void Main()
{
var hostEchoService = ConfigureWcfHost<EchoService, Contract.IEchoService>("EchoService");
ServiceHost hostEchoService = ConfigureWcfHost<EchoService, Contract.IEchoService>("EchoService");

hostEchoService.Open();

Expand Down
1 change: 1 addition & 0 deletions src/Samples/NetCoreClient/NetCoreClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

<ItemGroup>
<ProjectReference Include="..\StandardClient\Samples.StandardClient.csproj" />
<ProjectReference Include="..\StandardCommon\Samples.StandardCommon.csproj" />
</ItemGroup>

</Project>
17 changes: 11 additions & 6 deletions src/Samples/NetCoreClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ namespace NetCoreClient
{
class Program
{
private static readonly string s_hostname = "localhost";

static void Main()
/// <remarks>
/// use commanline argument localhost
/// or something similar to indicate the WCF Server hostname
/// </remarks>
static void Main(string[] args)
{
Settings settings = new Settings().SetDefaults(s_hostname, "EchoService");
string hostname = args.Length >= 1 ? args[0] : null;

Console.Title = "WCF .Net Core Client";
Settings settings = ClientLogic.BuildClientSettings(hostname);

static void log(string value) => Console.WriteLine(value);
ClientLogic.CallUsingWcf(settings, log);
ClientLogic.InvokeEchoServiceUsingWcf(settings, log);

string rawSoapResponse = ClientLogic.CallUsingWebRequest(settings.basicHttpAddress);
string rawSoapResponse = ClientLogic.InvokeEchoServiceUsingWebRequest(settings.basicHttpAddress);
Console.WriteLine($"Http SOAP Response:\n{rawSoapResponse}");

Console.WriteLine("Hit enter to exit");
Expand Down
14 changes: 12 additions & 2 deletions src/Samples/StandardClient/ClientLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,18 @@ namespace StandardClient
{
public class ClientLogic
{
public static Settings BuildClientSettings(string hostname)
{
const string s_hostname = "localhost";

string title = Console.Title;
if (string.IsNullOrWhiteSpace(hostname)) hostname = s_hostname;
Console.WriteLine(title + " - " + hostname);
Settings settings = new Settings().SetDefaults(hostname, "EchoService");
return settings;
}

public static void CallUsingWcf(
public static void InvokeEchoServiceUsingWcf(
Settings settings,
Action<string> log)
{
Expand Down Expand Up @@ -85,7 +95,7 @@ void RunExampleWsHttpsTransportWithMessageCredential ()
/// Creates a basic web request to the specified endpoint,
/// sends the SOAP request and reads the response
/// </summary>
public static string CallUsingWebRequest(Uri address)
public static string InvokeEchoServiceUsingWebRequest(Uri address)
{
string _soapEnvelopeContent =
@"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>
Expand Down
8 changes: 1 addition & 7 deletions src/Samples/StandardClient/IEchoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@ namespace Contract
[DataContract]
public class EchoFault
{
private string text;

[DataMember]
public string Text
{
get { return text; }
set { text = value; }
}
public string Text { get; set; }
}

[ServiceContract]
Expand Down

0 comments on commit f5f3fdc

Please sign in to comment.