标签: wcf-binding

以编程方式配置wcf服务

我有一个远程wcf服务,我通过WSHttpBinding连接它.如果我使用空服务构造函数,这意味着它将从app.config获取所有配置,一切正常,(我的意思是MyService s = new MyService()).现在我想以编程方式配置wcf.这很简单,直到我到达身份验证问题,这很难做到.这是我使用的app.config,你可以看到我的安全配置.

<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="SecuredEndPoint" closeTimeout="00:01:00" openTimeout="00:01:00"
                receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
                transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                allowCookies="false">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00"
                    enabled="true" />
                <security mode="Message">
                    <transport clientCredentialType="Windows" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" negotiateServiceCredential="true"
                        algorithmSuite="Default" />
                </security>
            </binding>               
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://MyWcfService.svc"
            binding="wsHttpBinding" bindingConfiguration="SecuredEndPoint"
            contract="ServiceReference1.IMyService" name="SecuredEndPoint">
            <identity>
                <certificate encodedValue="*******************************************************************" />
            </identity>
        </endpoint>            
    </client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

.net wcf wcf-binding wcf-security wcf-data-services

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

如何根据 if 条件以编程方式声明不同的 WCF 绑定类型?

我有一个以编程方式连接到 WCF 服务的 WinForms 客户端。这就是连接变量的声明方式...

var myBinding = new NetTcpBinding(); 
var myEndpoint = new EndpointAddress(myURI); 
var myChannelFactory = new ChannelFactory<IService>(myBinding, myEndpoint);
Run Code Online (Sandbox Code Playgroud)

但是,我想更改它,以便我可以根据 if 语句的结果使用不同的类(不仅仅是 NetTcpBinding)定义“myBinding”(相同的变量名称)。

这就是我想要的(我知道它不起作用,但请尝试理解我的意图)

if (bindingType == "BasicHttpBinding") { var myBinding = new BasicHttpBinding(); }
if (bindingType == "NetTcpBinding") { var myBinding = new NetTcpBinding(); }
if (bindingType == "WSHttpBinding") { var myBinding = new WSHttpBinding(); }
Run Code Online (Sandbox Code Playgroud)

谁能告诉我如何使用有效的方法实现相同的结果?同样,我想要的是能够根据 if 语句的结果定义“myBinding”。我也愿意考虑其他建议。谢谢

c# wcf wcf-binding

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

WCF - 无法获取元数据

它使用IIS 7在Intranet中运行,只要我在IIS管理器中启用匿名身份验证,它就可以正常工作.如果我禁用它并尝试使用wcftestclient运行它然后我得到以下错误,

Error: Cannot obtain Metadata from http://myserver/testing/eval.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address.  For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error    URI: http://myserver/testing/eval.svc    Metadata contains a reference that cannot be resolved: 'http://myserver/testing/eval.svc'.    The HTTP request is unauthorized with client authentication scheme 'Anonymous'. 
Run Code Online (Sandbox Code Playgroud)

这是我的web.config文件,

<system.serviceModel>
<bindings>
    <wsHttpBinding>
        <binding name="Binding1">
            <security mode="Transport">
                <transport clientCredentialType="Windows" …
Run Code Online (Sandbox Code Playgroud)

c# wcf wcftestclient wcf-binding wcf-security

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

WCF身份验证的问题

我有一个非常简单的WCF服务,我想公开公开.我创建了这项服务并将其设置在我们的服务器上,没有太多麻烦.问题是我们能够在我们的专用网络中使用该服务,但是当我们尝试从网络外部使用它时,会抛出以下错误:

安全支持提供程序接口(SSPI)协商失败.

我做了一些研究,听起来像WCF默认使用Windows身份验证.我想改变它以不使用身份验证,但我不完全确定如何.这是我的配置现在的样子.

<system.serviceModel>
    <services>
        <service behaviorConfiguration="XX.ZZ.WebService.MyServiceBehavior"
         name="XX.ZZ.WebService.MyService">
            <endpoint  address="" binding="wsHttpBinding" contract="XX.ZZ.WebService.IMyService">
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="XX.ZZ.WebService.MyServiceBehavior">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

我会很感激一些指示,或者在正确的方向上轻推.

.net wcf exception-handling wcf-binding wcf-security

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

WCF绑定-wsHttpBinding使用会话?

之前的一个帖子中,一位受访者表示使用wsHttpBinding使用了一个会话.由于我在群集IIS环境中工作,我应该禁用它吗?据我所知,会话在群集中不起作用.

如果我需要禁用此功能,我该如何解决?

iis session wcf-binding wshttpbinding

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

如何使用成员资格/授权在Azure上启用WCF服务的流传输?

我已经撞墙了,已经把头发拉了一段时间了.基本上,我需要创建一个具有ASP.NET成员资格和授权提供程序的WCF服务,但是它需要允许传输byte []数组或Stream对象并将它们保存到Azure.该服务本身托管在Azure上.

我遇到的问题是WCF需要消息层安全性来交换客户端凭据.所以我有以下配置,它运作得很好:

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior name="DefaultServiceBehavior">
        <serviceMetadata httpsGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="true" />
        <serviceAuthorization principalPermissionMode="UseAspNetRoles" roleProviderName="SqlRoleProvider" />
          <serviceCredentials>
            <serviceCertificate x509FindType="FindBySubjectName" storeName="My" storeLocation="LocalMachine" findValue="SecureChannelCertificate" />
            <userNameAuthentication userNamePasswordValidationMode="MembershipProvider"  membershipProviderName="SqlMembershipProvider" />
         </serviceCredentials>
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <bindings>
    <wsHttpBinding>
      <binding name="SecureBinding" messageEncoding="Mtom">
        <security mode="Message">
          <message clientCredentialType="UserName" negotiateServiceCredential="true" establishSecurityContext="true" />
        </security>
      </binding>
    </wsHttpBinding>
  </bindings>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

然后,需求发生了变化,现在我需要通过WCF服务将文件推送到Azure.无论我做什么,WCF都会因各种错误而尖叫我.

有谁知道如何配置服务,以便它可以使用身份验证/授权以及流媒体?

谢谢!

c# wcf wcf-binding azure wcf-security

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

WCF - 绑定错误

The endpoint at 'http://localhost:8731/Design_Time_Addresses/WCF/WCFService/' does not have a Binding with the None MessageVersion.  'System.ServiceModel.Description.WebHttpBehavior' is only intended for use with WebHttpBinding or similar bindings.
Run Code Online (Sandbox Code Playgroud)

这是我尝试启动WCF服务时遇到的错误.我在这里阅读了关于绑定错误的每篇文章,但它们都有点不同,我无法弄明白.这是我的app.config:

<system.serviceModel>
    <services>
      <service name="WCF.WCFService">
        <endpoint address="" binding="wsHttpBinding" contract="WCF.IWCFService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint
          address="mex"
          binding="mexHttpBinding"
          bindingConfiguration=""
          contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8731/Design_Time_Addresses/WCF/WCFService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior>
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

我在Windows服务中托管我的WCF服务,如果这有所不同.MY End的目标是使用winforms应用程序来使用WCF服务.当我在VS中运行WCF服务时,它可以工作,但是当我将配置添加到windows服务app.config并尝试用它启动WCF服务时,我收到错误.任何帮助都会很棒.

.net c# wcf windows-services wcf-binding

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

创建WCF绑定实例的XML表示

我正在尝试使用WSHttpBinding.CreateBindingElements方法中描述的方法编写代码以将WCF wsHttpBinding转换为customBinding .

Binding wsHttpBinding = ...
BindingElementCollection beCollection = originalBinding.CreateBindingElements();
foreach (var element in beCollection)
{
    customBinding.Elements.Add(element);
}
Run Code Online (Sandbox Code Playgroud)

生成自定义绑定后,我想为该新的自定义绑定生成XML表示.(与应用程序的.config文件中的XML表示形式相同).

有没有办法做到这一点?

(我知道这个答案中引用的工具:https://stackoverflow.com/a/4217892/5688,但我需要一些我可以在应用程序中调用的东西,而不依赖于云中的服务)

wcf wcf-binding

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

IIS上的WCF服务.如何摆脱URL路径中的"Service.svc"组件?

我在IIS上托管了WCF服务.出于商业原因,我不能发布此实例的公共URL,但我相信你会得到我的意思:

问题是,为了到达我的端点,似乎我已经包含Service.svc了路径段的一部分,即,我必须使用这样的URL:

http://<domain>/<app-name>/Service.svc/<relative-path>

我怎么能避免这个?我的意思是,我想通过以下方式访问我的服务:

http://<domain>/<app-name>/<relative-path>

当我在开发过程中自我托管服务时,我完全能够做到这一点.


最后,但这不是那么超然,浏览到http://<domain>/<AppName>/Service.svcURL会显示标准服务信息页面:

有没有办法可以防止这种情况发生?

在此输入图像描述

.net c# iis wcf wcf-binding

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

接收对我的服务的 HTTP 响应时出现 WCF 错误

大家好,我使用 WCF 创建了一个服务,但是当我测试我的服务时,有些服务成功完成,为什么有些服务给我下面的错误。关于如何解决这些问题有什么想法吗?谢谢

An error occurred while receiving the HTTP response to http://localhost:8733/PortOperation/Operator_Service/ws. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

Server stack trace: 
at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ClientReliableChannelBinder`1.RequestClientReliableChannelBinder`1.OnRequest(TRequestChannel channel, Message message, TimeSpan timeout, …
Run Code Online (Sandbox Code Playgroud)

.net c# wcf web-services wcf-binding

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