vs使用添加服务引用方式连接HTTPS协议的WCF服务
vs使用添加服务引用方式连接HTTPS协议的WCF服务
扫一扫加作者微信
客户端连接WCF服务,常用的两种连接方式:
1. 使用透明代理
2. 添加服务引用
下面将讲解添加服务引用方式连接WCF服务, 操作步骤:
1. VS解决方案,添加服务引用:
2. 输入https协议地址,点【转到】,若地址正确会显示WCF服务接口名称,
最后修改命名空间,如:MyCommonService,点【确定】按钮。
添加WCF服务引用后,VS会自动生成WCF接口的客户端代理类,
名字空间:MyCommonService
WCF代理类:MyCommonService.CommonServiceClient
WCF接口:MyCommonService.ICommonService
添加WCF服务引用后,App.config会自动生成binding/endpoint 配置:
XML Code:
<binding name="WSHttpBinding_ICommonService1">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
若服务器配置https协议,客户端:<security mode="Transport">
XML Code:
<endpoint address="https://cs5.manonwo.com/CommonService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ICommonService1"
contract="MyCommonService.ICommonService" name="WSHttpBinding_ICommonService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ICommonService1"
contract="MyCommonService.ICommonService" name="WSHttpBinding_ICommonService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
测试调用WCF服务接口:
C# Code:
private void button3_Click(object sender, EventArgs e)
{
byte[] loginTicket = GetLoginer();
MyCommonService.CommonServiceClient svc = new MyCommonService.CommonServiceClient();
//调用WCF接口,获取单据号码
var no = svc.GetDataSN(loginTicket, "AA", true);
ShowResult(no);
svc.Close();
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
{
byte[] loginTicket = GetLoginer();
MyCommonService.CommonServiceClient svc = new MyCommonService.CommonServiceClient();
//调用WCF接口,获取单据号码
var no = svc.GetDataSN(loginTicket, "AA", true);
ShowResult(no);
svc.Close();
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
获取单据号码,测试正常:
当WCF接口发生变动,比如添加接口、修改接口参数,此时客户端必须更新服务引用:
扫一扫加作者微信
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网