c# - How to set up a WCF client using wsDualHttpBinding in code? -


I need to connect to WCF service written to me without deploying app.config to the client application. I'm writing. However, I am trying to figure out how to install things from the customer side in code. This is as far as I've got ... Do I need to do anybody to do this work? I really appreciate it.

This is the code I received:

  string basepress = "http: // localhost / commservice"; WSDualHttp binding = new WSDualHttpBinding (); Binding .name = "WSDualHttpBinding_ICommService"; Binding. Clientbasedaddress = new URI (base address); Binding Reliable session. Fixed = true; Binding Reliable session. Inertia Time = New TimeSpain (0, 10, 0); Binding Receive timeout = new timespan (0, 10, 0); Binding.Sendetimeout = new timespan (0, 0, 5); Instant contact context = new instance contact (this); Client = New CommServiceClient (Reference, "WSDualHttpBinding_ICommService"); Client.Endpoint.Binding = Binding;  

And this is the app.config of the My Client app:

  & lt; System.serviceModel & gt; & Lt; Binding & gt; & Lt; WsDualHttpBinding & gt; & Lt; Binding name = "WSDualHttpBinding_ICommService" closeTimeout = "00:01:00" openTimeout = "00:01:00" receiveTimeout = "00:10:00" sendTimeout = "00:00:05" bypassProxyOnLocal = "false" transactionFlow = " False "hostNameComparisonMode =" StrongWildcard "maxBufferPoolSize =" 524288 "maxReceivedMessageSize =" 65536 "messageEncoding =" text "textEncoding =" utf-8 "useDefaultWebProxy =" true "& gt; & Lt; readerQuotas maxDepth = "32" maxStringContentLength = "8192" Makarere lang = "16384" Maksbaitspiyr Reed = "4096" maximum-Namteblkarn = "16384" / & gt; & Lt; Trusted session ordered = "true" idle time = "00:10:00" /> & lt; Security mode = "message" & gt; & Lt; Message Client Credential Type = "Windows" Conversation Service Credential = "True" AlgorithmSite = "Default" /> & Lt; / Safety & gt; & Lt; / Binding & gt; & Lt; / WsDualHttpBinding & gt; & Lt; / Binding & gt; & Lt; Customers & gt; & Lt; Endpoint address = "http: // localhost / commService /" bond = "wsDualHttpBinding" bindingConfiguration = "WSDualHttpBinding_ICommService" contract = "Services.ICommService" name = "WSDualHttpBinding_ICommService" & gt; & Lt; Identity & gt; & Lt; Dns value = "localhost" /> & Lt; / Identification & gt; & Lt; / Endpoint & gt; & Lt; / Customer & gt; & Lt; /system.serviceModel> You can easily get what you want to see the code given below:  

  Uri Bjedder = new Uri ("http: // localhost / CommService"); WSDualHttpBinding wsd = newWSDualHttpBinding (); Endpoint Address EA = New Endpoint Address (BaseEdress, Endpoint Indicity.Creditability ("localhost")); Client = new CommServiceClient (new instance contentbox (it), WSD, EA);  

Let me explain a bit:

  • generated app.config first we make an example of a WSDualHttpBinding with the default settings (those are exact) . If you want to modify any settings, you can change the properties that highlight them.
  • Then we create an EndPointAddress with the desired URL and identification. There is no need to link it with binding because we can link them all to the service client constructor.
  • In the end we create a service client, one of the contructor loads can specify us a binding and an endpoint address.
  • Normally every element or element in the app.config file available in each element or child element has an associated class one in the specified class in the associated asset.

Comments