2012-09-20 232 views
0

我使用visual studio 11添加服務(添加服務引用)。 當我加入該服務的文章,我有一個構造函數articleClient:綁定在客戶端+ WCF

public RssArticleServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
      base(binding, remoteAddress) { 
    } 

如何使用這個構造函數,我不知道我的結合應該使用哪個值?

任何示例或示例?

的Merci

問候


我這樣做:

BasicHttpSecurityMode securitymode = BasicHttpSecurityMode.Transport; BasicHttpBinding binding = new BasicHttpBinding(securitymode); binding.MaxReceivedMessageSize = int.MaxValue; binding.MaxBufferSize = int.MaxValue; Uri uri = new Uri("adresse/RssArticleService.svc";); _clientArticles = new RssArticleServiceClient(binding, new EndpointAddress("adresse/RssArticleService.svc";)); var result=await _clientArticles.GetRssDataAsync("1", "fr"); 

和一導管此錯誤:

**here was no endpoint listening at adresse/RssArticleService.svc that could accept the message. This is often caused by an incorrect address or SOAP** 

我能做些什麼,我應該改變綁定的類型?

回答

1

這是我實現:

BasicHttpSecurityMode securitymode = HostSource.Scheme.Equals("https", StringComparison.InvariantCultureIgnoreCase) ? BasicHttpSecurityMode.Transport : BasicHttpSecurityMode.None; 
BasicHttpBinding binding = new BasicHttpBinding(securitymode); 
binding.MaxReceivedMessageSize = int.MaxValue; 
binding.MaxBufferSize = int.MaxValue; 

Uri uri = new Uri(Application.Current.Host.Source, "../service.svc"); 
_client = new RssArticleServiceClient(binding, new EndpointAddress(uri)) 

編輯:你需要在你的web.config補充一點:

<system.serviceModel> 
<services> 
    <service name="namespace.RssArticleService" 
      behaviorConfiguration="RssArticleServiceBehavior"> 
    <endpoint address="" 
       binding="basicHttpBinding" 
       contract="namespace.IRssArticleService"/> 
    </service> 
</services> 
<serviceBehaviors> 
    <behavior name="RssArticleServiceBehavior"> 
     <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
    </behavior> 
</serviceBehaviors> 
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/> 
</system.serviceModel> 
+0

BasicHttpSecurityMode SECURITYMODE = BasicHttpSecurityMode.Transport; BasicHttpBinding binding = new BasicHttpBinding(securitymode); binding.MaxReceivedMessageSize = int.MaxValue; binding.MaxBufferSize = int.MaxValue; Uri uri = new Uri(「https://adresse/RssArticleService.svc」); _clientArticles = new RssArticleServiceClient(binding,new EndpointAddress(「https://adresse/RssArticleService.svc」)); var result = await _clientArticles.GetRssDataAsync(「1」,「fr」); – user1428798