0

我使用 Visual Studio 11 添加服务(添加服务参考)。当我添加服务文章时,我有一个带有一个构造函数的 articleClient:

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

我该如何使用这个构造函数,我不知道我应该使用哪个绑定值?

请提供任何示例或示例?

谢谢

此致


我这样做:

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");

和 A cat 这个错误:

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

我该怎么办,我应该更改绑定类型吗?

4

1 回答 1

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>
于 2012-09-20T14:30:19.127 回答