Guest User

Untitled

a guest
Dec 28th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. BasicHttpBinding binding = new BasicHttpBinding ();
  2.  
  3. Uri baseAddress = new Uri ("URL.svc");
  4.  
  5. EndpointAddress endpointAddress = new EndpointAddress (baseAddress);
  6.  
  7. var myChannelFactory = new ChannelFactory<IMyInterface> (binding, endpointAddress);
  8.  
  9. IMyInterface client = null;
  10.  
  11. try
  12. {
  13. client = myChannelFactory.CreateChannel ();
  14. var a = client.WsFunction ("XXXXXX");
  15. ((ICommunicationObject)client).Close ();
  16. }
  17. catch
  18. {
  19. if (client != null)
  20. {
  21. ((ICommunicationObject)client).Abort ();
  22. }
  23. }
  24.  
  25. [ServiceContract]
  26. public interface IMyInterface
  27. {
  28. [OperationContract]
  29. Result WsFunction1 (string param);
  30.  
  31. [OperationContract]
  32. Result WsFunction2 (string param);
  33.  
  34. [OperationContract]
  35. Result WsFunction3 (string param);
  36. }
  37.  
  38. [DataContract]
  39. public class Result
  40. {
  41. string a = "";
  42. string b = "";
  43.  
  44. [DataMember]
  45. public string A
  46. {
  47. get { return a; }
  48. set { a = value; }
  49. }
  50.  
  51. [DataMember]
  52. public string B
  53. {
  54. get { return b; }
  55. set { b = value; }
  56. }
  57. }
  58.  
  59. SLsvcUtil.exe /directory:C:usersmeDesktop http://URL.svc
  60.  
  61. var binding = new BasicHttpBinding() {
  62. Name = "BindingName",
  63. MaxBufferSize = 2147483647,
  64. MaxReceivedMessageSize = 2147483647
  65. };
  66.  
  67. var endpoint = new EndpointAddress("URL.svc");
  68.  
  69. MyInterfaceClient client = new MyInterfaceClient(binding, endpoint);
  70.  
  71. client.WSFunctionCompleted += (object sender, WSFunctionCompletedEventArgs e) => {
  72. //access e.Result here
  73. };
  74.  
  75. client.WSFunctionAsync("XXXXXX");
  76.  
  77. var binding = new BasicHttpBinding();
  78. binding.ProxyAddress = new Uri(string.Format("http://{0}:{1}", proxyAddress, proxyPort));
  79. binding.UseDefaultWebProxy = false;
  80. binding.Security.Mode = BasicHttpSecurityMode.Transport;
  81. binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
  82. binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Basic;
  83.  
  84. var endpoint = new EndpointAddress("serviceadress");
  85.  
  86. var authenticationClient = new WOKMWSAuthenticateClient(binding, endpoint);
  87. authenticationClient.ClientCredentials.UserName.UserName = username;
  88. authenticationClient.ClientCredentials.UserName.Password = password;
  89.  
  90. ServicePointManager.Expect100Continue = false;
Add Comment
Please, Sign In to add comment