tags:

views:

22

answers:

1

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();




    }
}

}

A: 

I hate to be snippy, but did it ever occur to you to actually show us the information that the exception has?

SOAP security negotiation with 'http://apcndaeazhao:9000/Service' for target 'http://apcndaeazhao:9000/Service' failed. See inner exception for more details

tells you that the exceptions inner exception (there is a property for that) has another exception that has the real error reason. THis is typical (wrapping an exception to make it easier to catch).

Now, sorry, my crystal ball is in repair, so I can not just look into it what the inner exception is. If you would actually look at it - and copy / paste it here - we could talk about the reason you get this error. As you did not do that, you will have to wait for an answer.

Could be anything of a number of things, and all would be revealed.... by looking at the inner exception.

TomTom
sorry, I don't know how to see the inner exception, the error message above is the only message I can catch using try catch
freedark81
No, this is not true. You stop in the catch, then open the exception in the debugger and look at the properties.
TomTom
thanks Tom, I see the inner message
freedark81
Inner Exception message is
freedark81
The message or signature supplied for verification has been altered
freedark81
but I still don't know how this happens
freedark81
By disable WFC security, this problem can work around, but is there a better way ?
freedark81