wp7分析IP知道你的位置
<!--LayoutRoot 是包含所有页面内容的根网格-->
<Grid x:Name="LayoutRoot" Background="#666">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel 包含应用程序的名称和页标题-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" FontSize="35" Text="我的应用程序" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock Foreground="Black" x:Name="PageTitle" Text="Ip 地址分析器" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - 在此处放置其他内容-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<TextBlock FontSize="35" Grid.Column="0" VerticalAlignment="Center" Text="IP地址:"/>
<TextBox Name="txtIP" Grid.Column="1"/>
<Button Grid.Column="2" Click="onQuery">
<Button.Content>
<Path Data="M0,10 L20,10 M5,0 L20,10 M5,20 L20,10"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Stroke="White" StrokeThickness="3"/>
</Button.Content>
</Button>
</Grid>
<StackPanel Grid.Row="1">
<TextBlock Foreground="Black" Name="txbTip"/>
<TextBlock Foreground="Black" TextWrapping="Wrap" Name="txbResult" Margin="2,12,2,0" FontSize="32" Height="140" Width="449" />
<TextBlock Foreground="Black" Height="373" FontSize="40" Name="textBlock1" Text="IP地址分析器,如果在同一网络的IP会直接提示与您在同一网络中,如果不是,则显示该IP的实际地址" TextWrapping="Wrap" />
</StackPanel>
</Grid>
</Grid>
后台代码:
private void onQuery(object sender, RoutedEventArgs e)
{
txbResult.Text = "";
// 第一步,实例化客户端代理类
IPQueryWebService.IpAddressSearchWebServiceSoapClient MyClient = new IPQueryWebService.IpAddressSearchWebServiceSoapClient();
// 第二步,绑定回调事件
MyClient.getCountryCityByIpCompleted += (s, arg) =>
{
// 取得结果
txbTip.Text = "请求完成。";
if (arg.Error != null)
{
txtIP.Text = string.Format("错误:{0}", arg.Error.Message);
return;
}
string[] res = arg.Result;
if (res != null)
{
if (res.Length > 1)
{
txbResult.Text = string.Format("结果查询:{0}", res[1]);
}
}
};
// 第三步,调用异步方法
txbTip.Text = "正在请求,请等候……";
MyClient.getCountryCityByIpAsync(txtIP.Text);
}
记得添加服务引用
http://webservice.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构