我需要在不添加服务引用的情况下访问 Wcf 服务方法?如何做到这一点?
第 1 步:我创建一个 WCF 服务。
第 2 步:将服务引用添加到我的应用程序。
第 3 步:并将 WCF 服务方法访问到应用程序中。
像这样,
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;
}
最佳答案
您可以按如下方式使用。只需确保添加服务契约(Contract)引用即可。
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");
来自 here你可以在这方面得到充分的锻炼。
关于c# - 是否可以在不添加服务引用的情况下访问 WCF 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19675194/