我正在构建一个应用程序,我需要在单击提交按钮时将表单中的数据发送到webservice。
我的数据将存储在网络服务中,如下所示:
<UserDetails>
<id>29</id>
<name>Golkonda Gajanan</name>
<street_address>ponna </street_address>
<city_address>Ichoda Adilabad </city_address>
<email_address>g17.golkonda@gmail.com</email_address>
<phone_no>9676101637</phone_no>
<zip_code>504307</zip_code>
<age>23</age>
<gender>Male</gender>
</UserDetails>
我的xaml是
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<TextBox GotFocus="OnGotFocus" Height="73" HorizontalAlignment="Left" Margin="18,45,0,0" Name="name" Text="Name" VerticalAlignment="Top" Width="419" />
<TextBox GotFocus="OnGotFocus1" Height="118" HorizontalAlignment="Left" Margin="18,108,0,0" Name="saddress" Text="Street Address" VerticalAlignment="Top" Width="419" />
<TextBox GotFocus="OnGotFocus2" Height="114" HorizontalAlignment="Left" Margin="18,213,0,0" Name="caddress" Text="City Address" VerticalAlignment="Top" Width="419" />
<TextBox GotFocus="OnGotFocus3" Height="70" HorizontalAlignment="Left" Margin="18,319,0,0" Name="email" Text="Email Address" VerticalAlignment="Top" Width="419" />
<TextBox GotFocus="OnGotFocus4" Height="76" HorizontalAlignment="Left" Margin="18,395,0,0" Name="phone" Text="Phone Number" VerticalAlignment="Top" Width="281" />
<TextBox GotFocus="OnGotFocus5" Height="69" HorizontalAlignment="Left" Margin="18,477,0,0" Name="zip" Text="Zip Code" VerticalAlignment="Top" Width="246" />
<TextBox GotFocus="OnGotFocus6" Height="69" HorizontalAlignment="Left" Margin="18,552,0,0" Name="age" Text="Age" VerticalAlignment="Top" Width="133" />
<RadioButton Content="Male" Height="75" HorizontalAlignment="Left" Margin="18,608,0,0" Name="radioButton1" VerticalAlignment="Top" Width="165" />
<RadioButton Content="Female" Height="72" HorizontalAlignment="Left" Margin="157,608,0,0" Name="radioButton2" VerticalAlignment="Top" Width="193" />
<Button Content="Submit" Height="71" HorizontalAlignment="Left" Margin="0,672,0,0" Name="submit" VerticalAlignment="Top" Width="163" Click="submit_Click" />
<Button Content="Reset" Height="71" HorizontalAlignment="Left" Margin="147,672,0,0" Name="reset" VerticalAlignment="Top" Width="152" />
<Button Content="Back" Height="71" HorizontalAlignment="Left" Margin="281,672,0,0" Name="back" VerticalAlignment="Top" Width="145" />
</Grid>
我的cs文件是
namespace KejriwalPhoneApp
{
public partial class Join : PhoneApplicationPage
{
public Join()
{
InitializeComponent();
}
private void submit_Click(object sender, RoutedEventArgs e)
{
if (name.Text == "")
{
MessageBox.Show("Please Enter the name");
name.Focus();
}
else
{
MessageBox.Show("Data submitted successfully");
}
}
private void OnGotFocus(object sender, RoutedEventArgs e)
{
if (name.Text.Equals("Name", StringComparison.OrdinalIgnoreCase))
{
name.Text = string.Empty;
}
}
private void OnGotFocus1(object sender, RoutedEventArgs e)
{
if (saddress.Text.Equals("Street Address", StringComparison.OrdinalIgnoreCase))
{
saddress.Text = string.Empty;
}
}
private void OnGotFocus2(object sender, RoutedEventArgs e)
{
if (caddress.Text.Equals("City Address", StringComparison.OrdinalIgnoreCase))
{
caddress.Text = string.Empty;
}
}
private void OnGotFocus3(object sender, RoutedEventArgs e)
{
if (email.Text.Equals("Email Address", StringComparison.OrdinalIgnoreCase))
{
email.Text = string.Empty;
}
}
private void OnGotFocus4(object sender, RoutedEventArgs e)
{
if (phone.Text.Equals("Phone Number", StringComparison.OrdinalIgnoreCase))
{
phone.Text = string.Empty;
}
}
private void OnGotFocus5(object sender, RoutedEventArgs e)
{
if (zip.Text.Equals("Zip Code", StringComparison.OrdinalIgnoreCase))
{
zip.Text = string.Empty;
}
}
private void OnGotFocus6(object sender, RoutedEventArgs e)
{
if (age.Text.Equals("Age", StringComparison.OrdinalIgnoreCase))
{
age.Text = string.Empty;
}
}
}
}
网络方法是registertoteam
答案 0 :(得分:1)
好。所以基本上,你需要做的就是在点击按钮时创建服务代理。 喜欢
var proxy = new ServiceProxy();
其中ServiceProxy是您的代理类,类的名称是您在添加引用时传递的名称
proxy.registerToTeam(your values here, better DTO object)
我会建议你
使用MVVM概念,为视图定义viewmodel
userDetails DTO对象,它将绑定到文本框和其他文件框 东西
使用ICommand接口进行命令。
以上所有内容都应使您的代码清晰。
答案 1 :(得分:0)
您无法以这种方式调用Web服务方法:
KejriwalService.aapSoapClient myclient = new KejriwalService.aapSoapClient();
myclient.registerToTeamCompleted +=
new EventHandler<KejriwalService.registerToTeamCompletedEventArgs>(myclient_gregisterToTeamCompleted);
myclient.registerToTeamAsync(name.Text, street_Address.Text
, city_address.Text, zip_code.Text
, email_address.Text, phone_no.Text
, age.Text, gender.Text
);