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.  Here’s the source code as an example.
PALACI is the address to call the AddressLookup service
public void btnFindAddress_Clicked(object sender, ClickedEventArgs e)
            XPathNavigator mynav = this.MainDataSource.CreateNavigator();
            XPathNavigator lstaddnode = mynav.SelectSingleNode(“”/my:myFields/my:lstaddresses””, NamespaceManager);
            FindAddressRequest findAddressRequest = BuildRequest();
            //calling the web service in managed code
            BasicHttpBinding binding = new BasicHttpBinding();
            //binding.Name = “”Soap11″”;
            EndpointAddress address = new EndpointAddress(“”″”);
            AddressLookupServiceClient client = new AddressLookupServiceClient(binding, address);
            FindAddressResponse findAddressResponse = client.FindAddress(findAddressRequest);
            StatusType status = findAddressResponse.Status;
            switch (status)
                case StatusType.SingleMatch:
                case StatusType.MultipleMatch:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s