WinForm 调用WebService 隐藏服务器IP地址之真假美猴王~!O(∩_∩)O哈哈~

 

  我们在WinForm项目中添加服务引用后会在App.config文件中添加如下内容:

  

 1 <?xml version="1.0" encoding="utf-8" ?>
 2 <configuration>
 3     <system.serviceModel>
 4         <bindings>
 5             <basicHttpBinding>
 6                 <binding name="TestServicePortBinding" />
 7             </basicHttpBinding>
 8         </bindings>
 9         <client>
10             <endpoint address="http://192.168.168.33:8080/WebTest/TestService"
11                 binding="basicHttpBinding" bindingConfiguration="TestServicePortBinding"
12                 contract="ServiceReference1.TestService" name="TestServicePort" />
13         </client>
14     </system.serviceModel>
15 </configuration>

 

  这样做虽然能够调用WebService却将服务器的IP地址暴露给了客户端。

 

  那么如何解决呢,老夫夜观天象,掐指一算~!搞个真假美猴王吧~!

  

1             WindowsFormsApplication4.ServiceReference1.TestServiceClient testServiceClient = new TestServiceClient();
2             testServiceClient.Endpoint.Address = new EndpointAddress("http://192.168.168.30:8080/WebTest/TestService");
3             testServiceClient.Endpoint.Binding = new BasicHttpBinding();
4             testServiceClient.Endpoint.ListenUri = new Uri("http://192.168.168.30:8080/WebTest/TestService");
5             MessageBox.Show(testServiceClient.jia(1, 2).ToString());

 

posted @ 2017-08-01 16:08  风中寻觅  阅读(492)  评论(0编辑  收藏  举报