I've been reading through Chapter 7 of the MS Infopath book (good reference). I have a C#/InfoPath project with a web service, where I've just converted from using Web References in VS.Net to the secondary data connections method, which is working just fine. My main reason was because I need to update the web service URL when I deliver this to our client, and I didn't want to have to change the code, but rather save the URL from our main application's web.config (it uses the same web service) and then get that URL from the pre-loaded InfoPath form.
I took the code from page 220 and set up a test case, where the adapter I'm using has the same web method on two servers, but will return a different result depending which is hit (so I know which was hit). When I run the function on page 220, I have an alert tell me that the nodeServiceUrl.text property is now set to the URL of the web service I want it to hit. However, when it then goes back to call the web service, it's giving me a result from the original URL. I can see the code changes the serviceURL, but it seems to leave the wsdlURL alone...could the discrepency be the problem?
Here's the code I modified into C# from page 220:
private void RebindWSAdapter(string adapterName, string wsURL)
{
Uri webserviceUrl;
WebServiceAdapter2 adapter;
IXMLDOMDocument2 xmlOperation;
IXMLDOMNode nodeServiceUrl;
webserviceUrl = new Uri(wsURL);
adapter = (WebServiceAdapter2) thisXDocument.DataAdapters[adapterName];
xmlOperation = (IXMLDOMDocument2) thisXDocument.CreateDOM();
xmlOperation.validateOnParse = false;
xmlOperation.loadXML(adapter.Operation);
nodeServiceUrl = xmlOperation.documentElement.selectSingleNode("@serviceUrl");
nodeServiceUrl.text = webserviceUrl.AbsoluteUri.ToString();
thisXDocument.UI.Alert("WS Adapter URL: " + nodeServiceUrl.text);
}
The call I make to this function is:
RebindWSAdapter("GetCheckoutStatusReceive", "http://server2/sites/PMDTC_Phase2/_vti_bin/pmdtc_svc.asmx");
The adapter code from my manifest.xsf file is:
<xsf:dataObjects>
<xsf:dataObject name="GetCheckoutStatusReceive" schema="GetCheckoutStatusReceive.xsd" initOnLoad="no">
<xsf:query>
<xsf:webServiceAdapter wsdlUrl="http://server1/sites/PMDTC_Phase2/_vti_bin/pmdtc_svc.asmx?WSDL" queryAllowed="yes" submitAllowed="no" name="GetCheckoutStatusReceive">
<xsf:operation name="GetCheckoutStatus" soapAction="http://tempuri.org/PMDTC.WebService/PMDTC_Phase2_WS/GetCheckoutStatus" serviceUrl="http://server1/sites/PMDTC_Phase2/_vti_bin/pmdtc_svc.asmx">
<xsf:input source="GetCheckoutStatusReceive.xml"></xsf:input>
</xsf:operation>
</xsf:webServiceAdapter>
</xsf:query>
</xsf:dataObject>
</xsf:dataObjects>