Sending Complex Type as argument to Secondary DataSource

C

Clayton

Is it possible to have a Secondary Data Source accept a complex data type as
an arguement?

Basically, in the form_submit, I would like to send my form as an arguement
and have the webservice return the database primary key back.

Currently it is sending my complex type as a literal string (encoded) and
not as a complex type.

My code:

public void FormEvents_Submit(object sender, SubmitEventArgs e)
{
try
{


XPathNavigator inputNav =
this.MainDataSource.CreateNavigator().SelectSingleNode("/my:MyTestInfoPathForm",
this.NamespaceManager);

WebServiceConnection receiveConnection =
(WebServiceConnection)this.DataConnections["WebServiceDS"];
XPathNavigator webServiceNavigator =
this.DataSources["PersistApplication2"].CreateNavigator();

// Set the arguements
webServiceNavigator.SelectSingleNode("/dfs:myFields/dfs:queryFields/ns1:WebServiceTest/ns1:formXml",
this.NamespaceManager).SetValue(inputNav.OuterXml); // Argument 1 of WS
webServiceNavigator.SelectSingleNode("/dfs:myFields/dfs:queryFields/ns1:WebServiceTest/my:dpaProxy",
this.NamespaceManager).SetValue(inputNav.InnerXml); // Arguement 2 of WS

receiveConnection.Execute();

// Get the returned value
XPathNavigator outputNav =
webServiceNavigator.SelectSingleNode("/dfs:myFields/dfs:dataFields/ns1:WebServiceTestResponse/ns1:persistApplicationResult",
this.NamespaceManager);

string uniqueKey = Convert.ToString(outputNav);

e.CancelableArgs.Cancel = false;
}
catch (Exception ex)
{
e.CancelableArgs.Cancel = true;
}
}
 
C

Clayton

To clarify, it is sending this:

<my:Contractor
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-12-03T17:10:25">

<my:ContractorName></my:ContractorName>

<my:ContractorAddressDescription></my:ContractorAddressDescription>

<my:ContractorMunicipality></my:ContractorMunicipality>

<my:ContractorProvince></my:ContractorProvince>

<my:ContractorCountry></my:ContractorCountry>

<my:ContractorPostalCode></my:ContractorPostalCode>

<my:ContractorTelephone></my:ContractorTelephone>

<my:ContractorCell></my:ContractorCell>

<my:ContractorFax></my:ContractorFax>

<my:ContractorEmail></my:ContractorEmail>

</my:Contractor>



But what I really need is

<my:Contractor
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-12-03T17:10:25">

<my:ContractorName></my:ContractorName>

<my:ContractorAddressDescription></my:ContractorAddressDescription>

<my:ContractorMunicipality></my:ContractorMunicipality>

<my:ContractorProvince></my:ContractorProvince>

<my:ContractorCountry></my:ContractorCountry>

<my:ContractorPostalCode></my:ContractorPostalCode>

<my:ContractorTelephone></my:ContractorTelephone>

<my:ContractorCell></my:ContractorCell>

<my:ContractorFax></my:ContractorFax>

<my:ContractorEmail></my:ContractorEmail>

</my:Contractor>


Clayton said:
Is it possible to have a Secondary Data Source accept a complex data type
as an arguement?

Basically, in the form_submit, I would like to send my form as an
arguement and have the webservice return the database primary key back.

Currently it is sending my complex type as a literal string (encoded) and
not as a complex type.

My code:

public void FormEvents_Submit(object sender, SubmitEventArgs e)
{
try
{


XPathNavigator inputNav =
this.MainDataSource.CreateNavigator().SelectSingleNode("/my:MyTestInfoPathForm",
this.NamespaceManager);

WebServiceConnection receiveConnection =
(WebServiceConnection)this.DataConnections["WebServiceDS"];
XPathNavigator webServiceNavigator =
this.DataSources["PersistApplication2"].CreateNavigator();

// Set the arguements

webServiceNavigator.SelectSingleNode("/dfs:myFields/dfs:queryFields/ns1:WebServiceTest/ns1:formXml",
this.NamespaceManager).SetValue(inputNav.OuterXml); // Argument 1 of WS

webServiceNavigator.SelectSingleNode("/dfs:myFields/dfs:queryFields/ns1:WebServiceTest/my:dpaProxy",
this.NamespaceManager).SetValue(inputNav.InnerXml); // Arguement 2 of WS

receiveConnection.Execute();

// Get the returned value
XPathNavigator outputNav =
webServiceNavigator.SelectSingleNode("/dfs:myFields/dfs:dataFields/ns1:WebServiceTestResponse/ns1:persistApplicationResult",
this.NamespaceManager);

string uniqueKey = Convert.ToString(outputNav);

e.CancelableArgs.Cancel = false;
}
catch (Exception ex)
{
e.CancelableArgs.Cancel = true;
}
}
 
B

BobCh

Have you tried calling the Webservice from a dataconnection and
setting the arguments through the web service call (instead of in
code)?

I have a webservice with the following string args,

Public Function Contact_IU_from_XML(ByVal aContactXML As String,
ByVal aIndustriesXML As String, ByVal asInterestsXML As String, ByVal
asContactCategoryXML As String) As Integer

and in the Data Connection wizard I have
Field or group: /ns3:myFields
Submit data as a string.

In the service I create an xmlreader from the fragment and the known
schema.

hth.

To clarify, it is sending this:

&lt;my:Contractor
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-12-03T17..."&gt;

&lt;my:ContractorName&gt;&lt;/my:ContractorName&gt;

&lt;my:ContractorAddressDescription&gt;&lt;/my:ContractorAddressDescription&gt;

&lt;my:ContractorMunicipality&gt;&lt;/my:ContractorMunicipality&gt;

&lt;my:ContractorProvince&gt;&lt;/my:ContractorProvince&gt;

&lt;my:ContractorCountry&gt;&lt;/my:ContractorCountry&gt;

&lt;my:ContractorPostalCode&gt;&lt;/my:ContractorPostalCode&gt;

&lt;my:ContractorTelephone&gt;&lt;/my:ContractorTelephone&gt;

&lt;my:ContractorCell&gt;&lt;/my:ContractorCell&gt;

&lt;my:ContractorFax&gt;&lt;/my:ContractorFax&gt;

&lt;my:ContractorEmail&gt;&lt;/my:ContractorEmail&gt;

&lt;/my:Contractor&gt;

But what I really need is

<my:Contractor
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-12-03T17...">

<my:ContractorName></my:ContractorName>

<my:ContractorAddressDescription></my:ContractorAddressDescription>

<my:ContractorMunicipality></my:ContractorMunicipality>

<my:ContractorProvince></my:ContractorProvince>

<my:ContractorCountry></my:ContractorCountry>

<my:ContractorPostalCode></my:ContractorPostalCode>

<my:ContractorTelephone></my:ContractorTelephone>

<my:ContractorCell></my:ContractorCell>

<my:ContractorFax></my:ContractorFax>

<my:ContractorEmail></my:ContractorEmail>

</my:Contractor>


Is it possible to have a Secondary Data Source accept a complex data type
as an arguement?
Basically, in the form_submit, I would like to send my form as an
arguement and have the webservice return the database primary key back.
Currently it is sending my complex type as a literal string (encoded) and
not as a complex type.
public void FormEvents_Submit(object sender, SubmitEventArgs e)
{
try
{
XPathNavigator inputNav =
this.MainDataSource.CreateNavigator().SelectSingleNode("/my:MyTestInfoPathForm",
this.NamespaceManager);
WebServiceConnection receiveConnection =
(WebServiceConnection)this.DataConnections["WebServiceDS"];
XPathNavigator webServiceNavigator =
this.DataSources["PersistApplication2"].CreateNavigator();
// Set the arguements
webServiceNavigator.SelectSingleNode("/dfs:myFields/dfs:queryFields/ns1:WebServiceTest/ns1:formXml",
this.NamespaceManager).SetValue(inputNav.OuterXml); // Argument 1 of WS
webServiceNavigator.SelectSingleNode("/dfs:myFields/dfs:queryFields/ns1:WebServiceTest/my:dpaProxy",
this.NamespaceManager).SetValue(inputNav.InnerXml); // Arguement 2 of WS

// Get the returned value
XPathNavigator outputNav =
webServiceNavigator.SelectSingleNode("/dfs:myFields/dfs:dataFields/ns1:WebServiceTestResponse/ns1:persistApplicationResult",
this.NamespaceManager);
string uniqueKey = Convert.ToString(outputNav);
e.CancelableArgs.Cancel = false;
}
catch (Exception ex)
{
e.CancelableArgs.Cancel = true;
}
}
 
C

Clayton

The reason why I want to pass the complex type is my form will be rather
large and it would be a lot easier if I had a strongly typed object on the
webservice side to work with.

If I could somehow deserialize the XML to a class (or pass the complex type)
it would make my life a lot easier...

Currently, my code does pretty much the same thing as your data connection
wizard except I have some logic after the submit that does stuff with the
primary key returned from the web service





BobCh said:
Have you tried calling the Webservice from a dataconnection and
setting the arguments through the web service call (instead of in
code)?

I have a webservice with the following string args,

Public Function Contact_IU_from_XML(ByVal aContactXML As String,
ByVal aIndustriesXML As String, ByVal asInterestsXML As String, ByVal
asContactCategoryXML As String) As Integer

and in the Data Connection wizard I have
Field or group: /ns3:myFields
Submit data as a string.

In the service I create an xmlreader from the fragment and the known
schema.

hth.

To clarify, it is sending this:

&lt;my:Contractor
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-12-03T17..."&gt;

&lt;my:ContractorName&gt;&lt;/my:ContractorName&gt;

&lt;my:ContractorAddressDescription&gt;&lt;/my:ContractorAddressDescription&gt;

&lt;my:ContractorMunicipality&gt;&lt;/my:ContractorMunicipality&gt;

&lt;my:ContractorProvince&gt;&lt;/my:ContractorProvince&gt;

&lt;my:ContractorCountry&gt;&lt;/my:ContractorCountry&gt;

&lt;my:ContractorPostalCode&gt;&lt;/my:ContractorPostalCode&gt;

&lt;my:ContractorTelephone&gt;&lt;/my:ContractorTelephone&gt;

&lt;my:ContractorCell&gt;&lt;/my:ContractorCell&gt;

&lt;my:ContractorFax&gt;&lt;/my:ContractorFax&gt;

&lt;my:ContractorEmail&gt;&lt;/my:ContractorEmail&gt;

&lt;/my:Contractor&gt;

But what I really need is

<my:Contractor
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-12-03T17...">

<my:ContractorName></my:ContractorName>

<my:ContractorAddressDescription></my:ContractorAddressDescription>

<my:ContractorMunicipality></my:ContractorMunicipality>

<my:ContractorProvince></my:ContractorProvince>

<my:ContractorCountry></my:ContractorCountry>

<my:ContractorPostalCode></my:ContractorPostalCode>

<my:ContractorTelephone></my:ContractorTelephone>

<my:ContractorCell></my:ContractorCell>

<my:ContractorFax></my:ContractorFax>

<my:ContractorEmail></my:ContractorEmail>

</my:Contractor>


Is it possible to have a Secondary Data Source accept a complex data
type
as an arguement?
Basically, in the form_submit, I would like to send my form as an
arguement and have the webservice return the database primary key back.
Currently it is sending my complex type as a literal string (encoded)
and
not as a complex type.
public void FormEvents_Submit(object sender, SubmitEventArgs e)
{
try
{
XPathNavigator inputNav =
this.MainDataSource.CreateNavigator().SelectSingleNode("/my:MyTestInfoPathForm",
this.NamespaceManager);
WebServiceConnection receiveConnection =
(WebServiceConnection)this.DataConnections["WebServiceDS"];
XPathNavigator webServiceNavigator =
this.DataSources["PersistApplication2"].CreateNavigator();
// Set the arguements
webServiceNavigator.SelectSingleNode("/dfs:myFields/dfs:queryFields/ns1:WebServiceTest/ns1:formXml",
this.NamespaceManager).SetValue(inputNav.OuterXml); // Argument 1 of WS
webServiceNavigator.SelectSingleNode("/dfs:myFields/dfs:queryFields/ns1:WebServiceTest/my:dpaProxy",
this.NamespaceManager).SetValue(inputNav.InnerXml); // Arguement 2 of
WS

// Get the returned value
XPathNavigator outputNav =
webServiceNavigator.SelectSingleNode("/dfs:myFields/dfs:dataFields/ns1:WebServiceTestResponse/ns1:persistApplicationResult",
this.NamespaceManager);
string uniqueKey = Convert.ToString(outputNav);
e.CancelableArgs.Cancel = false;
}
catch (Exception ex)
{
e.CancelableArgs.Cancel = true;
}
}
 
B

BobCh

Passing it as string and then serializing it into an xmlreader from
the fragment and the known schema is what I do.

' Create the reader for the provided XML Fragment.
Dim reader As XmlReader = XmlReader.Create(New
StringReader(aContactXML))
Dim _ContactDS As New DataSet("Contact")
_ContactDS.ReadXml(reader) ' Populate a temp datset with
the revalent rows
reader.Close()
aContactRow = _ContactDS.Tables(0).Rows(0) ' Create a
shorthand name

The reason why I want to pass the complex type is my form will be rather
large and it would be a lot easier if I had a strongly typed object on the
webservice side to work with.

If I could somehow deserialize the XML to a class (or pass the complex type)
it would make my life a lot easier...

Currently, my code does pretty much the same thing as your data connection
wizard except I have some logic after the submit that does stuff with the
primary key returned from the web service


Have you tried calling the Webservice from a dataconnection and
setting the arguments through the web service call (instead of in
code)?
I have a webservice with the following string args,
Public Function Contact_IU_from_XML(ByVal aContactXML As String,
ByVal aIndustriesXML As String, ByVal asInterestsXML As String, ByVal
asContactCategoryXML As String) As Integer
and in the Data Connection wizard I have
Field or group: /ns3:myFields
Submit data as a string.
In the service I create an xmlreader from the fragment and the known
schema.

To clarify, it is sending this:
&lt;my:Contractor
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-12-03T17..."&gt;
&lt;my:ContractorName&gt;&lt;/my:ContractorName&gt;
&lt;my:ContractorAddressDescription&gt;&lt;/my:ContractorAddressDescription&gt;
&lt;my:ContractorMunicipality&gt;&lt;/my:ContractorMunicipality&gt;
&lt;my:ContractorProvince&gt;&lt;/my:ContractorProvince&gt;
&lt;my:ContractorCountry&gt;&lt;/my:ContractorCountry&gt;
&lt;my:ContractorPostalCode&gt;&lt;/my:ContractorPostalCode&gt;
&lt;my:ContractorTelephone&gt;&lt;/my:ContractorTelephone&gt;
&lt;my:ContractorCell&gt;&lt;/my:ContractorCell&gt;
&lt;my:ContractorFax&gt;&lt;/my:ContractorFax&gt;
&lt;my:ContractorEmail&gt;&lt;/my:ContractorEmail&gt;
&lt;/my:Contractor&gt;
But what I really need is
<my:Contractor
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-12-03T17...">
<my:ContractorName></my:ContractorName>
<my:ContractorAddressDescription></my:ContractorAddressDescription>
<my:ContractorMunicipality></my:ContractorMunicipality>
<my:ContractorProvince></my:ContractorProvince>
<my:ContractorCountry></my:ContractorCountry>
<my:ContractorPostalCode></my:ContractorPostalCode>
<my:ContractorTelephone></my:ContractorTelephone>
<my:ContractorCell></my:ContractorCell>
<my:ContractorFax></my:ContractorFax>
<my:ContractorEmail></my:ContractorEmail>
</my:Contractor>

Is it possible to have a Secondary Data Source accept a complex data
type
as an arguement?
Basically, in the form_submit, I would like to send my form as an
arguement and have the webservice return the database primary key back.
Currently it is sending my complex type as a literal string (encoded)
and
not as a complex type.
My code:
public void FormEvents_Submit(object sender, SubmitEventArgs e)
{
try
{
XPathNavigator inputNav =
this.MainDataSource.CreateNavigator().SelectSingleNode("/my:MyTestInfoPathForm",
this.NamespaceManager);
WebServiceConnection receiveConnection =
(WebServiceConnection)this.DataConnections["WebServiceDS"];
XPathNavigator webServiceNavigator =
this.DataSources["PersistApplication2"].CreateNavigator();
// Set the arguements
webServiceNavigator.SelectSingleNode("/dfs:myFields/dfs:queryFields/ns1:WebServiceTest/ns1:formXml",
this.NamespaceManager).SetValue(inputNav.OuterXml); // Argument 1 of WS
webServiceNavigator.SelectSingleNode("/dfs:myFields/dfs:queryFields/ns1:WebServiceTest/my:dpaProxy",
this.NamespaceManager).SetValue(inputNav.InnerXml); // Arguement 2 of
WS
receiveConnection.Execute();
// Get the returned value
XPathNavigator outputNav =
webServiceNavigator.SelectSingleNode("/dfs:myFields/dfs:dataFields/ns1:WebServiceTestResponse/ns1:persistApplicationResult",
this.NamespaceManager);
string uniqueKey = Convert.ToString(outputNav);
e.CancelableArgs.Cancel = false;
}
catch (Exception ex)
{
e.CancelableArgs.Cancel = true;
}
}
 
Top