Featured post
How to call WCF Service that requires Headers from Silverlight -
wcf 3.5 sp1 services / called silverlight 4
in situation vendor has created wcf api, both svc services, custom proxy client.
both aspects of api sit on top of core four-layer abstraction.
first there 2 abstract messagecontract classes: wcfrequest , wcfresponse.
the abstract wcfrequest type contains properties decorated messageheader attribute, , contain things such custom authentication identifier , timezone.
then there second layer of onion each method divided 2 classes: getsomethingrequest , getsomethingresponse, both of inherit wcfrequest , wcfreponse, respectively.
next comes implementation layer, wcfrequest , wcfresponse based types bubble , invoked custom wcfclient type, controls channelfactory construction, establishes binding, , importantly, sets identifier header in wcfrequest type based on set value in memory (like session key).
lastly comes view ouside world, request poco types via id values.
now, api written in such way if use vendor supplied proxy, things work expected - authentication occurs , identifier set, , can call method call without problem.
if you've made far, sticking me.
now, problem occurs when want write silverlight client, using either "add service reference" or slsvcutil, none of proxy client types generated have these header properties wcfrequest header set, , not defined in message prototype parameters pass in.
to set these headers, i've looked @ wcfextras project on codeplex , tried use clientsoapheaderhelper routines, doesn't work silverlight (no extension capability).
i've tried operationcontext - see if set header there, that's null - @ least if inspect in client proxy method.
are person knows how manually (hack) these headers place?
thanks assistance...but totally understand if gets no hits.
i ran in problem of custom headers while ago... needed write headers little differently internal classes wanted (it apache service).
here way got around (three classes).
inside operation context create new instance of headerserializer class. class based on headerserializerbase (my class too) based on xmlobjectserializer. headerserializerbase uses writeraw write string in header (in case stored in app, build dynamically no problems).
hth :)
using (operationcontextscope ocs = new operationcontextscope(client.innerchannel)) { var ser = new headerserializer(); operationcontext.current.outgoingmessageheaders.add(messageheader.createheader("securityheader", "http://somesite.com/schema", authheader, ser)); var req = new getpredefinedsearchresultsrequest() { someproperty = somevalue }; client.getpredefinedsearchresultsasync(req); } public class headerserializer : headerserializerbase { public epgheaderserializer() { base.autheheaderstring = xamlingcore.infrastructure.resource.resourceloader.loadstringresource("assembly.data", "rawheaderdata.txt"); } } public class headerserializerbase : xmlobjectserializer { protected string autheheaderstring; public override void writestartobject(xmldictionarywriter writer, object graph) { throw new notimplementedexception(); } public override void writeobjectcontent(xmldictionarywriter writer, object graph) { writer.writeraw(autheheaderstring.tochararray(), 0, autheheaderstring.length); } public override void writeendobject(xmldictionarywriter writer) { throw new notimplementedexception(); } public override object readobject(xmldictionaryreader reader, bool verifyobjectname) { throw new notimplementedexception(); } public override bool isstartobject(xmldictionaryreader reader) { throw new notimplementedexception(); } }
- Get link
- X
- Other Apps
Comments
Post a Comment