Share via


Calling a WCF service from Infopath

Recently I got into a scenario where I wanted to call a WCF service from within an Infopath Form service, Infopath does not supports configuration files so my service was not able to pick the Binding and Endpoint setting for the Service at the client side

To resolve I programmatically created a channel for the service to connect, works like a charm

EndpointAddress address = new EndpointAddress("https://localhost:12346/XXXXXXX\Abc.svc");

BasicHttpBinding binding = new BasicHttpBinding();

DocumentGen docgen = ChannelFactory<DocumentGen>.CreateChannel (binding,address);

GenerateRequestBody body = new GenerateRequestBody(PackageInstance);

GenerateRequest request = new GenerateRequest(body);

GenerateResponse response = docgen.Generate(request);

 

Basically the <MethodName>Request and <MethodName>Response classes are generated along with proxy when you add a service reference to your project, <MethodName>Request requires a <MethodName>RequestBody object to specify the parameter to be passed to the service.

Comments