Created
May 5, 2014 21:59
-
-
Save Isaac-Kleinman/31b77274623ca309e754 to your computer and use it in GitHub Desktop.
A first attempt at configuring the SOAP request programmatically
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
AsymmetricSecurityBindingElement sec; | |
sec = (AsymmetricSecurityBindingElement) SecurityBindingElement.CreateMutualCertificateBindingElement( | |
MessageSecurityVersion.WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10); | |
sec.DefaultAlgorithmSuite = SecurityAlgorithmSuite.TripleDesRsa15; | |
sec.IncludeTimestamp = false; | |
sec.AllowSerializedSigningTokenOnReply = true; | |
sec.MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncrypt; | |
sec.EndpointSupportingTokenParameters.Signed.Add( new UserNameSecurityTokenParameters( )); | |
CustomBinding binding = new CustomBinding(); | |
binding.Elements.Add(sec); | |
binding.Elements.Add(new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8)); | |
binding.Elements.Add(new HttpsTransportBindingElement()); | |
EndpointIdentity ei = new DnsEndpointIdentity( "DPMedsHistory"); | |
EndpointAddress ea = new EndpointAddress( new Uri("https://service01.emedny.org:7602/MHService"), | |
ei, new AddressHeaderCollection()); | |
mhsClient = new MHSClient( binding, ea ); | |
mhsClient.ClientCredentials.ServiceCertificate.DefaultCertificate = | |
new X509Certificate2( // make the server certificate availble here ); | |
mhsClient.ClientCredentials.ClientCertificate.Certificate = | |
new X509Certificate2( // make your client certificate available here ); | |
mhsClient.ClientCredentials.UserName.UserName = "username"; | |
// this is a password you establish with eMedNy especially for this purpose | |
mhsClient.ClientCredentials.UserName.Password = "password"; | |
mhsClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = | |
System.ServiceModel.Security.X509CertificateValidationMode.None; | |
Transaction request = new Transaction(); | |
request.transData = Encoding.UTF8.GetBytes( "270 message" ); | |
Transaction response; | |
response = mhsClient.getEligibility( request ); | |
string _271Message = Encoding.UTF8.GetString( response.transData ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment