2013-05-30 49 views
0

我想在Asp.net中使用WCF服務我在Web站點添加引用。我不想更新我的Web.Config文件。在代碼中設置WCF服務配置在ASP.net

我想從代碼Behind.All配置屬性處理WCF服務像

WSHttpBinding 
EndpointIdentity 
Uri 
ContractDescription 

手柄形式後面的代碼。

回答

1

您需要使用地址創建一個終點,並且還需要基於Web服務支持的綁定,您可以創建綁定,然後您只需創建代理並使用該服務。

// 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