Created
November 29, 2012 14:38
-
-
Save awrowse/4169494 to your computer and use it in GitHub Desktop.
SOAP Client RN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.ServiceModel; | |
using System.ServiceModel.Channels; | |
using RightNow.AddIns.AddInViews; | |
using RightNow.AddIns.Common; | |
using System.AddIn; | |
using System.Windows.Forms; | |
using HelloAgent.RNSoap; | |
namespace PS.Utility { | |
public class SoapClient { | |
private static volatile SoapClient _instance = null; | |
private static object syncRoot = new Object(); | |
public RightNowSyncPortClient RNService; | |
private ClientInfoHeader _clientInfoHeader; | |
public ClientInfoHeader clientInfoHeader { | |
get { | |
if (_clientInfoHeader == null) { | |
_clientInfoHeader = new ClientInfoHeader(); | |
_clientInfoHeader.AppID = "Demo App"; | |
} | |
return _clientInfoHeader; | |
} | |
set { _clientInfoHeader = value; } | |
} | |
private CreateProcessingOptions _createProcessingOptions; | |
public CreateProcessingOptions createProcessingOptions { | |
get { | |
if (_createProcessingOptions == null) { | |
_createProcessingOptions = new CreateProcessingOptions(); | |
_createProcessingOptions.SuppressExternalEvents = true; | |
_createProcessingOptions.SuppressRules = true; | |
} | |
return _createProcessingOptions; | |
} | |
set { _createProcessingOptions = value; } | |
} | |
private GetProcessingOptions _getProcessingOptions; | |
public GetProcessingOptions getProcessingOptions { | |
get { | |
if (_getProcessingOptions == null) { | |
_getProcessingOptions = new GetProcessingOptions(); | |
_getProcessingOptions.FetchAllNames = true; | |
} | |
return _getProcessingOptions; | |
} | |
set { _getProcessingOptions = value; } | |
} | |
private SoapClient() | |
{ | |
IGlobalContext _globalContext = AutomationClient.GlobalContext; | |
string url = _globalContext.InterfaceURL; | |
url = url.Replace("http:", "https:"); | |
url = url.Replace("/php/", "/services/soap"); | |
EndpointAddress endPointAddr = new EndpointAddress(url); | |
//EndpointAddress endPointAddr = new EndpointAddress(_globalContext.GetInterfaceServiceUrl(ConnectServiceType.Soap)); | |
//EndpointAddress endPointAddr = new EndpointAddress("https://<site>/cgi-bin/<interface>.cfg/services/soap"); | |
// Minimum required | |
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential); | |
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName; | |
// Optional depending upon use cases | |
binding.MaxReceivedMessageSize = 1024 * 1024; | |
binding.MaxBufferSize = 1024 * 1024; | |
binding.MessageEncoding = WSMessageEncoding.Mtom; | |
// Create client proxy class | |
RNService = new RightNowSyncPortClient(binding, endPointAddr); | |
// Ask the Add-In framework the handle the session logic | |
//_globalContext.PrepareConnectSession(RNService.ChannelFactory); | |
RNService.ClientCredentials.UserName.UserName = "training_user"; | |
RNService.ClientCredentials.UserName.Password = "TrainUser1234!"; | |
// Ask the client to not send the timestamp | |
BindingElementCollection elements = RNService.Endpoint.Binding.CreateBindingElements(); | |
elements.Find<SecurityBindingElement>().IncludeTimestamp = false; | |
RNService.Endpoint.Binding = new CustomBinding(elements); | |
} | |
//Double checked locking is supported by .NET | |
public static SoapClient GetInstance() | |
{ | |
if (_instance == null) | |
{ | |
lock (syncRoot) | |
{ | |
if (_instance == null) | |
{ | |
_instance = new SoapClient(); | |
} | |
} | |
} | |
return _instance; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment