we have soap based web service , able read wsdl when type in url in browser. sit behind proxy in our network not blocking , able read wsdl using browser.but when enter url in browser http://ist.services/coreservices/coreservices?wsdl
asks username , password not same windows credentials. when enter username , password shared dev team , returns wsdl page. please note webservice developed , deployed on java based server.
how do same in c#.net code , how pass security crednetials in discoveryclientprotocol? tried below code works webservices doesn't ask security credentials.
// specify url discover. string sourceurl = "http://ist.services/coreservices/coreservices?wsdl"; string outputdirectory = "c:\\temp"; discoveryclientprotocol client = new discoveryclientprotocol(); var credentials = new networkcredential("sunuser1", "xxxxxxx", ""); webproxy proxy = new webproxy("http://proxy.bingo:8000/", true) { credentials = credentials }; client.credentials = credentials; // use default credentials access url being discovered. //client.credentials = credentials;//credentialcache.defaultcredentials; client.proxy = proxy; string discovermode = "discoverany"; string resolvemode = "resolveall"; try { discoverydocument doc; // check see if whether user wanted read in existing discovery results. if (discovermode == "readall") { discoveryclientresultcollection results = client.readall(path.combine("c:\\temp", "results.discomap")); //savemode.value = "nosave"; } else { // check see if whether user wants capability discover kind of discoverable document. if (discovermode == "discoverany") { doc = client.discoverany(sourceurl); } else // discover discovery documents, might contain references other types of discoverable documents. { doc = client.discover(sourceurl); } // check see whether user wants resolve possible references supplied url. if (resolvemode == "resolveall") client.resolveall(); else { // check see whether user wants resolve references nested more 1 level deep. if (resolvemode == "resolveonelevel") client.resolveonelevel(); else console.writeline("empty"); } } } catch (exception e2) { //discoveryresultsgrid.columns.clear(); //status.text = e2.message; console.writeline(e2.message); } // if documents discovered, display results in data grid. if (client.documents.count > 0) console.writeline(client); } }
since code didn't me , opened fiddler trace http calls when manual read wsdl in browser , see takes credentials entered "authorization: basic cgdfddsfdfsdsfdsgsgfg=" . in fiddler see 3 calls responses 401,302 , 200. in c#.net code don't 200 response , throws me 404 error.
i further debugged , in httpresponse of client object see flag status invocation_flags_initialized | invocation_flags_need_security
so looks need pass credentials security credentials rather network credentials.
the below code has fixed issue.
credentialcache mycredentialcache = new credentialcache { { new uri(sourceurl), "basic", networkcredential } }; discoveryclientprotocol.allowautoredirect = true; discoveryclientprotocol.credentials = mycredentialcache;
Comments
Post a Comment