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(“”http://palaci.ourcheshire.cccusers.com:8448/AddressLookup.Service/AddressLookupService.svc/Soap11″”);
            AddressLookupServiceClient client = new AddressLookupServiceClient(binding, address);
            client.Open();
            FindAddressResponse findAddressResponse = client.FindAddress(findAddressRequest);
            client.Close();
            StatusType status = findAddressResponse.Status;
            switch (status)
            {
                case StatusType.SingleMatch:
                    AssignSingleResult(findAddressResponse);
                    break;
                case StatusType.MultipleMatch:
                    AssignMultipleResults(findAddressResponse);
                    break;
                default:
                    break;
            }
        }

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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