c# - Calling an external service method channel factory client -


how call service method using channelfactory. here's code create 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 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 proxyclient class ..

finally want 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 way soap request is, mr. google gave me following link:

wcf ws-security , wse nonce authentication - rick strahl's web log

so check somehow, have make channelfactory call service method. external service. grt!!

client.somemethod();  

also, here webrequest trying 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 wsdl also..


Comments