I have a small solution contains 3 projects, one is the Service library, the second is a self host console application, the third is the client console application. after I build the solution, I copy the client.exe to anther machine, then run the self host app and client.exe, but on client machine, got below errors: "SOAP security negotiation with 'http://apcndaeazhao:9000/Service' for target 'http://apcndaeazhao:9000/Service' failed. See inner exception for more details." but if I run client.exe and self host app on one machine, it is Ok
I am a beginner in WCF and with little knowledage about it, I do not know why this happen, so could anyone help me on this problem, thanks in advance
Below is the script:
IService.cs
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
// TODO: Add your service operations here
}
// Use a data contract as illustrated in the sample below to add composite types to service operations
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
service.cs
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}
SelfHosting.cs
namespace SelfHosting { class Program { static void Main(string[] args) {
ServiceHost host = new ServiceHost(typeof(MyWcfServiceLibrary.Service1));
ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(MyWcfServiceLibrary.IService1), new WSHttpBinding(), "http://apcndaeazhao:9000/Service");
host.Open();
Console.WriteLine("Service is running !");
Console.WriteLine("{0} ({1})",
endpoint.Address.ToString(),
endpoint.Binding.Name);
Console.ReadLine();
}
}
}
Client.cs
namespace Client { class Program { static void Main(string[] args) {
IService1 channel = null;
EndpointAddress endaddress = new EndpointAddress("http://apcndaeazhao:9000/Service");
channel = ChannelFactory<IService1>.CreateChannel(new WSHttpBinding(), endaddress);
Console.WriteLine("Press any key ...");
Console.ReadLine();
try
{
string str = channel.GetData(10);
Console.WriteLine(str);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.ReadLine();
}
}
}