我需要访问Wcf服务方法而不添加服务引用?如何做到这一点?
第1步:我创建一个WCF服务.
第2步:向我的应用程序添加服务引用.
第3步:将WCF服务方法访问到app.
像这样,
ServiceReference1.Service1Client obj = new ServiceReference1.Service1Client();
protected void Button1_Click(object sender, EventArgs e)
{
UserDetails userInfo = new UserDetails();
userInfo.UserName = TextBoxUserName.Text;
userInfo.Password = TextBoxPassword.Text;
userInfo.Country = TextBoxCountry.Text;
userInfo.Email = TextBoxEmail.Text;
string result = obj.InsertUserDetails(userInfo);
LabelMessage.Text = result;
}
Run Code Online (Sandbox Code Playgroud)
Thi*_*a H 22
您可以使用如下.只需确保添加服务合同参考.
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress("http://localhost:4684/Service1.svc");
ChannelFactory factory = new ChannelFactory<ServiceContract>(binding, address);
ServiceContract channel = factory.CreateChannel();
string resturnmessage = channel.YourMethod("test");
Run Code Online (Sandbox Code Playgroud)
从这里你可以得到充分的锻炼.
归档时间: |
|
查看次数: |
30593 次 |
最近记录: |