0

How would I call a service method using ChannelFactory. Here's my code to create the ChannelFactory:

var b=new CustomBinding();
var sec=(AsymmetricSecurityBindingElement)SecurityBindingElement.CreateMutualCertificateBindingElement(MessageSecurityVersion.WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10);

sec.EndpointSupportingTokenParameters.Signed.Add(new UserNameSecurityTokenParameters());
sec.MessageSecurityVersion=MessageSecurityVersion.WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10;
sec.IncludeTimestamp=true;
sec.MessageProtectionOrder=System.ServiceModel.Security.MessageProtectionOrder.EncryptBeforeSign;

b.Elements.Add(sec);
b.Elements.Add(new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8));
b.Elements.Add(new HttpTransportBindingElement());

AddressHeader addressHeader=AddressHeader.CreateAddressHeader("wsse", "http://12.23.28.113:9047/MHService", 1);
AddressHeader[] addressHeaders=new AddressHeader[1] { addressHeader };
EndpointAddress endptAddress=new EndpointAddress(new Uri("http://12.23.28.113:9047/MHService"), EndpointIdentity.CreateDnsIdentity("DPMedsHistory"), addressHeaders);
ChannelFactory<IRequestChannel> channelFactory=null;
channelFactory=new ChannelFactory<IRequestChannel>(b, endptAddress);
UsernameClientCredentials credentials=new UsernameClientCredentials(new UsernameInfo("USER", "PWD"));

// replace ClientCredentials with UsernameClientCredentials
channelFactory.Endpoint.Behaviors.Remove(typeof(ClientCredentials));
channelFactory.Endpoint.Behaviors.Add(credentials);
channelFactory.Credentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.My, X509FindType.FindBySubjectName, "Mycer1");
channelFactory.Credentials.ServiceCertificate.SetDefaultCertificate(StoreLocation.CurrentUser, StoreName.My, X509FindType.FindBySubjectName, "Mycer");
IRequestChannel serviceProxy=channelFactory.CreateChannel();

This is my ProxyClient class ..

Finally this is what I want to do:

MHSClient serviceProxy = new MHSClient(b, endptAddress);
byte[] array=Encoding.ASCII.GetBytes(s);
Transaction t=new Transaction();
t.transData=array;
serviceProxy.getEligibility(t);

But because of the way my SOAP request is, Mr. Google gave me the following link:

WCF WS-Security and WSE Nonce Authentication - Rick Strahl's Web Log

So now to check it somehow, I have to make this ChannelFactory call the service method. This is an external service. Something like this would be grt!!

client.somemethod(); 

Also, here is the webrequest I am trying to generated..

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mhs="http://org/emedny/mhs/" xmlns:urn="urn:hl7-org:v3">
    <soapenv:Header>
    <wsse:Security soap:mustUnderstand="1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
    <wsse:BinarySecurityToken ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="SecurityToken-e00c8062-83d2-4f04-88fc-996218e7bb3d">MIICeDCC....(eMedNY signed user MLS cert).......</wsse:BinarySecurityToken>
    <wsse:BinarySecurityToken ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="SecurityToken-c0cc2cd4-cb77-4fa5-abfa-bd485afd1685">MIIDFj.....( eMedNY MLS web-service end-point public cert)........</wsse:BinarySecurityToken>
    <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="SecurityToken-970e9a80-00cc-4c86-8ec4-3ba16e029a5b">
    <wsse:Username>....your_username.....</wsse:Username>
    <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">.....your_plaintext_password....</wsse:Password>
    <wsse:Nonce>KNyu6MsXCkTg4DDyvwvEiw==</wsse:Nonce>
    <wsu:Created>2010-09-15T18:00:30Z</wsu:Created>
    </wsse:UsernameToken>
    <xenc:EncryptedKey xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
    <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5"/>
    <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
    <wsse:SecurityTokenReference>
    <wsse:Reference URI="#SecurityToken-c0cc2cd4-cb77-4fa5-abfa-bd485afd1685" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
    </wsse:SecurityTokenReference>
    </KeyInfo>
    <xenc:CipherData>
    <xenc:CipherValue>gpBAWt91pdwhKva............</xenc:CipherValue>
    </xenc:CipherData>
    <xenc:ReferenceList>
    <xenc:DataReference URI="#Enc-0641b860-b16d-4941-91c0-d60bece67794"/>
    </xenc:ReferenceList>
    </xenc:EncryptedKey>
    <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
    <SignedInfo>

I have the wsdl also..

  • http://stackoverflow.com/questions/15539072/is-it-possible-to-get-rid-of-the-tclient-generic-type-in-the-service-class/15603873#15603873 – Ken Kin May 06 '13 at 06:31
  • @ Ken Kin This is getting too complicated.. All to add a ws security username token with nonce, password digest to my client.. The service is external. i have no control over it. But the blogs have this IRequestChannel.. I am pretty sure it is for the client... – user2299574 May 07 '13 at 01:33
  • Ah, complicated .. really? I see your code is more complicated than the OP's code of that question. – Ken Kin May 07 '13 at 01:37
  • @Ken Kin: :) Can you think of any other ways to generate my webrequest. I am editing my question to show the header to be generated. I am not sure if its supposed to be so complicated.. Actually, only the channel factory stuff seems complicated for me.. The rest is all bindings and setting credentials.. – user2299574 May 07 '13 at 15:13
  • If the linked answer doesn't meet your requirement, then I cannot simply have you an answer with the current content I can see in the question. Since it looked specific and particular, and the whole `project/solution` would be required to solve your problem in practice. – Ken Kin May 07 '13 at 17:03

0 Answers0