标签: wcf-configuration

wsHttpBinding更改为客户端app.config中的basicHttpBinding

在WCF服务中,我将端点绑定设置为wsHttpBinding.但是,当我使用Visual Studio添加服务引用时,我的客户端app.config将绑定显示为basicHttpBinding.有人知道为什么会这样吗?

服务web.config中的My Endpoint(在IIS 7.5中托管).从baseAddresses获取地址

<endpoint address=""
    binding="wsHttpBinding"
    bindingConfiguration="wsHttpServiceBinding"
    contract="MyProject.IMyService" />
Run Code Online (Sandbox Code Playgroud)

客户端app.config:

<client>
    <endpoint address="http://example.com/MyService.svc"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_MyService"
    contract="Service.MyService" name="BasicHttpBinding_MyService" />
</client>
Run Code Online (Sandbox Code Playgroud)

.net wcf wcf-binding wcf-configuration

5
推荐指数
1
解决办法
5500
查看次数

App.config外的WCF ChannelFactory配置?

我有一个使用插件系统的Windows服务.我在插件基类中使用以下代码为每个DLL提供单独的配置(因此它将从中读取plugin.dll.config):

string dllPath = Assembly.GetCallingAssembly().Location;
return ConfigurationManager.OpenExeConfiguration(dllPath);
Run Code Online (Sandbox Code Playgroud)

这些插件需要调用WCF服务,因此我遇到的问题是new ChannelFactory<>("endPointName")只在托管应用程序的App.config中查找端点配置.

有没有办法简单地告诉ChannelFactory查看另一个配置文件或以某种方式注入我的Configuration对象?

我能想到的唯一方法是从读入的值手动创建EndPoint和Binding对象plugin.dll.config,并将它们传递给其中一个ChannelFactory<>重载.这看起来真的像重新创建了一个轮子,并且它可能会因为大量使用行为和绑定配置而变得非常混乱. 也许通过传递配置部分可以轻松创建EndPoint和Binding对象?

c# wcf wcf-configuration

5
推荐指数
1
解决办法
4740
查看次数

WCF 测试客户端 - 有什么方法可以将服务/设置保存到文件中以便以后轻松重新加载?

WCF 测试客户端是一个非常强大的工具。我可以避免创建新的控制台应用程序来测试我的服务。然而,令人讨厌的是我似乎无法保存我添加到客户端的服务/配置。如果我关闭它并再次打开它,它会重新开始。

有什么方法可以保存 WCF 测试客户端的“实例”……有点像 FxCop 如何让您扫描二进制文件并将该设置保存到 FxCop 文件?

wcf wcftestclient wcf-configuration

5
推荐指数
1
解决办法
2072
查看次数

将应用程序配置嵌入到WCF中的C#代码中

我有一个客户端程序连接到我的wcf服务。我想将应用程序配置嵌入C#代码中,直到用户无法更改甚至看不到app.config为止。

但是我不能将这两个配置设置带到C#代码中:

<system.diagnostics>
    <sources>
      <source propagateActivity="true" name="System.ServiceModel" switchValue="Warning">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="NewListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging" switchValue="Warning,ActivityTracing" >
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="NewListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add initializeData="Trace.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
          name="NewListener" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack">
        <filter type="" />
      </add>
    </sharedListeners>
  </system.diagnostics>
Run Code Online (Sandbox Code Playgroud)

<system.net>
    <defaultProxy enabled="true" useDefaultCredentials="true" >
      <proxy autoDetect="True" …
Run Code Online (Sandbox Code Playgroud)

c# configuration wcf wcf-client wcf-configuration

5
推荐指数
1
解决办法
2259
查看次数

如何解决WCF中的System.ServiceModel.ServerTooBusyException?

我正在开发一个每天平均有 50,000 次访问(大约 140,000 页面浏览量)的网站。我正在使用WCF作为我的服务InstanceContextMode = InstanceContextMode.PerCall
此外,我正在使用异步方法来调用 WCF 服务,
最近我在某些页面和某些请求上收到以下异常消息:

Exception Type: System.ServiceModel.ServerTooBusyException
Exception Message: The HTTP service located at http://localhost:8090/SmartService.svc is unavailable.  This could be because the service is too busy or because no endpoint was found listening at the specified address. Please ensure that the address is correct and try accessing the service again later.
Stack Trace:    at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.<>c__DisplayClass5`1.<CreateGenericTask>b__4(IAsyncResult asyncResult)
   at …
Run Code Online (Sandbox Code Playgroud)

c# wcf exception wcf-configuration asynchronous-wcf-call

5
推荐指数
1
解决办法
1万
查看次数

WCF在随机调用中获取"在接收到HTTP响应时发生错误"

我从客户端调用SOAP API时,随机接收(并非总是)"接收到HTTP响应出错".它不会每次都发生.我的应用程序本身是一个WCF服务.

客户端配置:

<binding name="AbcBinding" 
                 sendTimeout="00:02:45"
                 closeTimeout="00:02:45"
                 openTimeout="00:02:45"
                 receiveTimeout="00:10:00"
                 bypassProxyOnLocal="false"
                 maxBufferPoolSize="2147483647" 
                 maxReceivedMessageSize="2147483647">
            <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
                <security mode="Transport" >
                <transport clientCredentialType="Basic" />
                </security>
        </binding>

<client>
      <endpoint binding="basicHttpBinding" bindingConfiguration="AbcBinding"
                contract="AbcContract" name="AbcBinding" />
    </client>
Run Code Online (Sandbox Code Playgroud)

码:

var configFactory = new ConfigurationChannelFactory<AbcContract>("AbcBinding"), ConfigFile, "localhost:9198/AbcCall");

            #region Basic http authentication
            if (configFactory.Credentials != null)
            {
                    var defaultCredentials = configFactory.Endpoint.Behaviors.Find<ClientCredentials>();
                    configFactory.Endpoint.Behaviors.Remove(defaultCredentials);

                    var loginCredentials = new ClientCredentials();
                    loginCredentials.UserName.UserName = "UserName";
                    loginCredentials.UserName.Password = "Password";
                    configFactory.Endpoint.Behaviors.Add(loginCredentials);

            }
Run Code Online (Sandbox Code Playgroud)

编辑 在本地环境中,它可以正常工作,具有以下配置:useDefaultWebProxy="false" proxyAddress="http://127.0.0.1:8888"

但在部署服务器上,我遇到以上配置错误: …

wcf wcf-client wcf-configuration .net-4.5.2

5
推荐指数
1
解决办法
166
查看次数

一切都可以在WCF中以编程方式完成,还是某些功能的配置文件?

我非常喜欢使用代码,利用IntelliSense并开放C#语言的所有功能来使用WCF,但我想确保我不会朝着最终限制WCF功能集的方向前进我可以访问.我的经验是如此受限于WCF,我不明白使用配置文件的好处,特别是如果你可以在代码中做所有事情(?).

注意:我使用的是.NET 3.5.

您能以编程方式使用WCF执行"一切"还是完整WCF功能集所需的配置文件?

wcf wcf-configuration

4
推荐指数
1
解决办法
609
查看次数

将属性添加到BehaviorExtensionElement

我正在为WCF添加一个自定义behaviorExtensionElement,并希望添加一个在读取配置元素时可以读取的属性,例如

<system.serviceModel>
    <extensions>
      <behaviorExtensions>
        <add name="myExtension"
             type="Bar.FooBarElement, Bar"/>
      </behaviorExtensions>
    </extensions>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <myExtension myAttribute="Foo" />
Run Code Online (Sandbox Code Playgroud)

但是,我收到错误"无法识别的属性'myAttribute'.请注意,属性名称区分大小写."

我怎么能避免这个?如何在代码中读取myAttribute值?

configuration wcf wcf-configuration servicebehavior

4
推荐指数
1
解决办法
4004
查看次数

如何在WCF服务中启用HTTPS

我在IIS上托管了我的服务.

托管服务已应用SSL证书,在浏览URL时,它显示为HTTPS.

但是,当我将此URL用于客户端应用程序(ASP.NET WEB应用程序)时,它允许添加,https//domain/service.svc但在客户端配置中,它会显示URL http而不是https.什么时候手动更改,它会给出如下错误:The provided URI scheme 'https' is invalid; expected 'http'.

以下是WCF服务配置(在IIS上托管):

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="customBehavior">
      <serviceMetadata httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

<bindings>
  <basicHttpBinding>
    <binding name="basicBindingConfiguration" closeTimeout="00:05:00"
            openTimeout="00:05:00" receiveTimeout="00:10:00" sendTimeout="00:05:00"
            allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
            maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
            messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
            useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
          maxBytesPerRead="4096" maxNameTableCharCount="16384" />

      <security mode="None">

      </security>
    </binding>
  </basicHttpBinding>
</bindings>

<serviceHostingEnvironment  multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="0" />
<services>
  <service name="Administrator.OAP.CRMServices.CRMServices"
           behaviorConfiguration="customBehavior">
    <endpoint address=""
              binding="basicHttpBinding"
              bindingConfiguration="basicBindingConfiguration"
              contract="Administrator.OAP.CRMServices.Contracts.ICRMServices" />
  </service> …
Run Code Online (Sandbox Code Playgroud)

https wcf basichttpbinding wcf-security wcf-configuration

4
推荐指数
1
解决办法
2万
查看次数

尝试在ASP.NET网站中托管时出现WCF服务异常错误

尝试浏览我的.svc文件时发生以下错误.

An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.NullReferenceException: Object reference not set to an instance of an object.
   at System.ServiceModel.Description.WsdlExporter.CreateWsdlBindingAndPort(ServiceEndpoint endpoint, XmlQualifiedName wsdlServiceQName, Port& wsdlPort, Boolean& newBinding, Boolean& bindingNameWasUniquified)
   at System.ServiceModel.Description.WsdlExporter.ExportEndpoint(ServiceEndpoint endpoint, XmlQualifiedName wsdlServiceQName)
   at System.ServiceModel.Description.WsdlExporter.ExportEndpoints(IEnumerable`1 endpoints, XmlQualifiedName wsdlServiceQName)
   at System.ServiceModel.Description.ServiceMetadataBehavior.MetadataExtensionInitializer.GenerateMetadata()
   at System.ServiceModel.Description.ServiceMetadataExtension.EnsureInitialized()
   at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.InitializationData.InitializeFrom(ServiceMetadataExtension extension)
   at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.GetInitData()
   at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.TryHandleDocumentationRequest(Message httpGetRequest, String[] queries, Message& replyMessage)
   at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.ProcessHttpRequest(Message httpGetRequest)
   at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.Get(Message message)
   at SyncInvokeGet(Object , Object[] , Object[] )
   at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& …
Run Code Online (Sandbox Code Playgroud)

c# wcf exception-handling .net-4.0 wcf-configuration

3
推荐指数
1
解决办法
1万
查看次数

如何以编程方式在托管服务上设置服务主体名称

要使用配置文件执行上述操作,我会这样做:

<endpoint
  address="...."
  binding="netTcpBinding"
  bindingConfiguration="MyBinding"
  contract="IService1">
  <identity>
    <servicePrincipalName value="name"/>
  </identity>
</endpoint>
Run Code Online (Sandbox Code Playgroud)

但是如何将其添加到下面的代码中?

Uri uri = new Uri("http://example.com/service");
ServiceHost host = new ServiceHost(typeof(Service1), uri);

NetTcpBinding binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.Message;
binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
host.AddServiceEndpoint(typeof(IService1), binding, uri);
host.Open();
Run Code Online (Sandbox Code Playgroud)

.net c# wcf wcf-client wcf-configuration

0
推荐指数
1
解决办法
3884
查看次数