c# - Consuming a secured Web Service -
i'm new in consuming web services , have access state-run web service. given app.config file, certificate file (.cer) , general instructions.
haven'n used visual studio 2008 express before have 15 years experience in writing vb5/6 code.
anyway, installed .cer file using mmc , opened new project , added system.runtime.serialization , system.servicemodel addedd service reference wsdl link included app.config file in project , wrote following code.
using system; using system.collections.generic; using system.linq; using system.text; namespace echosvcclientconsappl { class program { static void main(string[] args) { conap66.myserviceref.serviceclient clientproxy = new conap66.myserviceref.serviceclient(); clientproxy.clientcredentials.username.username = "xx"; clientproxy.clientcredentials.username.password = "xx"; clientproxy.open(); if (clientproxy != null) system.console.writeline("init succeeded "); else system.console.writeline("init error"); string ar1 = "xxx"; string ar2 = "xxx"; string ar3 = "xxx"; conap66.myserviceref.eres r = clientproxy.getres1(ar1, ar2, ar3); if (r.status != null) system.console.writeline("ok"); else system.console.writeline(r.error); clientproxy.close(); system.console.readline(); } } }
i error on line: conap66.myserviceref.eres r = clientproxy.getres1(ar1, ar2, ar3);
saying have token authentication problems
any clues??? appreciated since don't know do...
update:
i added trace app.config , got:
security processor unable find security header in message. might because message unsecured fault or because there binding mismatch between communicating parties. can occur if service configured security , client not using security.
after googling found out should put enableunsecuredresponse="true" in app.config
i did that, nothing happened
i think need accept certificate server follow.
public static bool certhandler(object sender, x509certificate certificate, x509chain chain, sslpolicyerrors error) { // says accept certificate. // in production environment have check if can accept certificate. return true; } servicepointmanager.servercertificatevalidationcallback = certhandler;
add these lines before proxy creation.
namespace of servicepointmanager class system.net.
namespace of x509certificate class system.security.cryptography.
Comments
Post a Comment