.net - WCF ChannelFactory with Custom Endpoint Behavior (Json-Rpc) -
i've been working hard on wcf json-rpc service model. i'm new wcf , wcf extensibility i'm able process requests web browser :) summarize it, i've implemented endpoint behavior, operation selector, , message formatter.
you can find latest source code on post on msdn forum.
i'm trying create wcf client i'm stuck following error:
manual addressing enabled on factory, messages sent must pre-addressed.
this how i'm creating client:
private int communicationtimeout = 10; private int communicationport = 80; private string jsonrpcroot = "/json.rpc"; public void initializeclient() { uri baseaddress = new uribuilder(uri.urischemehttp, environment.machinename, communicationport, jsonrpcroot).uri; endpointaddress address = new endpointaddress(baseaddress.absoluteuri); channelfactory<ijsonservice> channelfactory = new channelfactory<ijsonservice>(new webhttpbinding(), address); channelfactory.endpoint.behaviors.add(new jsonrpcendpointbehavior()); ijsonservice typedproxy = channelfactory.createchannel(); int = typedproxy.starttransport(10); }
and (test) service contract. kept simple possible
[servicecontract(namespace = "")] public interface ijsonservice { [operationcontract] ilist<mission> getmissions(); [operationcontract] int starttransport(int missionid); [operationcontract] int transportcompleted(int missionid); }
the answer question lying in message formatter.
the error indicates message built , returned wcf stack, doesn't contain address.
in order satisfy rule, iclientmessageformatter should include value in
message.headers.to
i've changed iclientmessageformatter.serializerequest implementation following:
public message serializerequest(messageversion messageversion, object[] parameters) { string jsontext = serializejsonrequestparameters(parameters); // compose message message message = message.createmessage(messageversion, _clientoperation.action, new jsonrpcbodywriter(encoding.utf8.getbytes(jsontext))); message.properties.add(webbodyformatmessageproperty.name, new webbodyformatmessageproperty(webcontentformat.raw)); _address.applyto(message); httprequestmessageproperty reqprop = new httprequestmessageproperty(); reqprop.headers[httprequestheader.contenttype] = "application/json"; message.properties.add(httprequestmessageproperty.name, reqprop); uribuilder builder = new uribuilder(message.headers.to); builder.query = string.format("jsonrpc={0}", httputility.urlencode(jsontext)); message.headers.to = builder.uri; message.properties.via = builder.uri; return message; }
Comments
Post a Comment