我想在Asp.net中使用WCF服务我在网站上添加了参考。我不想更新我的Web.Config文件。
我想从Code Behind处理WCF服务。所有配置属性如
WSHttpBinding
EndpointIdentity
Uri
ContractDescription
处理后面的表单代码。
答案 0 :(得分:1)
您需要使用地址创建端点,并且还需要基于Web服务支持的绑定,您可以创建Binding,然后您将创建代理并使用该服务。
// Specify an end point address of the service
EndpointAddress endpointAdress = new EndpointAddress(serviceUrl);
// Create the binding to be used by the service
BasicHttpBinding binding1 = new BasicHttpBinding();
//customize the binding configurations like the ones below
binding.SendTimeout = TimeSpan.FromMinutes( 1 );
binding.OpenTimeout = TimeSpan.FromMinutes( 1 );
binding.CloseTimeout = TimeSpan.FromMinutes( 1 );
binding.ReceiveTimeout = TimeSpan.FromMinutes( 10 );
//create the client proxy using the specific endpoint and binding you have created
YourServiceClient proxy = new YourServiceClient(binding1, endpointAddress);
或者您可以使用ChannelFactory
来遵循操作指南here