WCF change endpoint address at runtime

后端 未结 4 669
囚心锁ツ
囚心锁ツ 2020-11-28 04:43

I have my first WCF example working. I have the host on a website which have many bindings. Because of this, I have added this to my web.config.



        
4条回答
  •  野性不改
    2020-11-28 05:11

    So your endpoint address defined in your first example is incomplete. You must also define endpoint identity as shown in client configuration. In code you can try this:

    EndpointIdentity spn = EndpointIdentity.CreateSpnIdentity("host/mikev-ws");
    var address = new EndpointAddress("http://id.web/Services/EchoService.svc", spn);   
    var client = new EchoServiceClient(address); 
    litResponse.Text = client.SendEcho("Hello World"); 
    client.Close();
    

    Actual working final version by valamas

    EndpointIdentity spn = EndpointIdentity.CreateSpnIdentity("host/mikev-ws");
    Uri uri = new Uri("http://id.web/Services/EchoService.svc");
    var address = new EndpointAddress(uri, spn);
    var client = new EchoServiceClient("WSHttpBinding_IEchoService", address);
    client.SendEcho("Hello World");
    client.Close(); 
    

提交回复
热议问题