app config - How to set system.net settings inside wpf application -
app config - How to set system.net settings inside wpf application -
in wpf project getting error:
private void btnretrieve_click(object sender, routedeventargs e) { uri uri = new uri("http://10.214.36.245", urikind.absolute); using (webclient wc = new webclient()) { byte[] barr = wc.downloaddata(uri); string sdata = new string(barr.select(a => convert.tochar(a)).toarray()); tbretrieveddata.text = sdata; } }
it same in windows form application:
private void btnclicked(object sender, eventargs e) { webclient wc = new webclient(); var c = wc.downloaddata("http://10.214.36.245"); }
solution in the server committed protocol violation. section=responsestatusline error.
in windows form application easy:
but don't know how implement solution wpf application. if added app.config file , changed it's content according solution shows error:
ps: it's runtime code below don't want utilize solution because doesn't give me using of app.config file in wpf application :
public static bool setallowunsafeheaderparsing20() { //get assembly contains internal class assembly anetassembly = assembly.getassembly(typeof(settingssection)); if (anetassembly != null) { //use assembly in order internal type internal class type asettingstype = anetassembly.gettype("system.net.configuration.settingssectioninternal"); if (asettingstype != null) { //use internal static property instance of internal settings class. //if static instance isn't created allready property create us. object aninstance = asettingstype.invokemember("section", bindingflags.static | bindingflags.getproperty | bindingflags.nonpublic, null, null, new object[] { }); if (aninstance != null) { //locate private bool field tells framework unsafe header parsing should allowed or not fieldinfo auseunsafeheaderparsing = asettingstype.getfield("useunsafeheaderparsing", bindingflags.nonpublic | bindingflags.instance); if (auseunsafeheaderparsing != null) { auseunsafeheaderparsing.setvalue(aninstance, true); homecoming true; } } } } homecoming false; }
wpf app-config webclient system.net
Comments
Post a Comment