我花了很多时间搞清楚如何配置我的WCF服务,以便它们适用于生产环境中的https.
基本上,我需要这样做:
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
<services>
<service name="MyNamespace.MyService" behaviorConfiguration="MyServiceBehavior">
<endpoint address="" bindingNamespace="https://secure.mydomain.com" binding="basicHttpBinding" bindingConfiguration="HttpsBinding" contract="MyNamespace.IMyService"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="HttpsBinding">
<security mode="Transport">
<transport clientCredentialType="None"></transport>
</security>
</binding>
</basicHttpBinding>
</bindings>
Run Code Online (Sandbox Code Playgroud)
将bindingNamespace属性添加到端点是使其工作的最终因素.
但是这个配置在我在常规http下工作的本地开发环境中不起作用.所以我的配置是:
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
<services>
<service name="MyNamespace.MyService" behaviorConfiguration="MyServiceBehavior">
<endpoint address="" binding="basicHttpBinding" contract="MyNamespace.IMyService"/>
</service>
</services>
Run Code Online (Sandbox Code Playgroud)
这里的区别是我将httpsGetEnabled属性设置为false,并删除了bindingConfiguration和bindingNamespace.
问题是: …
我已经编写了一个WCF Web服务供Silverlight应用程序使用.最初,该服务仅需要基本的http绑定.我们现在需要能够部署服务以在http和https下使用.我找到了web.config的一些设置,允许我按如下方式执行此操作:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="SilverlightFaultBehavior">
<silverlightFaults />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="CxtMappingWebService.CxtMappingWebServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="SecureHttpBinding">
<security mode="Transport" />
</binding>
<binding name="BasicHttpBinding">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="CxtMappingWebService.CxtMappingWebService" behaviorConfiguration="CxtMappingWebService.CxtMappingWebServiceBehavior">
<endpoint address="" bindingConfiguration="SecureHttpBinding" binding="basicHttpBinding" contract="CxtMappingWebService.ICxtMappingWebService" behaviorConfiguration="SilverlightFaultBehavior" />
<endpoint address="" bindingConfiguration="BasicHttpBinding" binding="basicHttpBinding" contract="CxtMappingWebService.ICxtMappingWebService" behaviorConfiguration="SilverlightFaultBehavior" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
然而不幸的是,这有一个问题.
此Web服务需要部署到数百个客户的服务器上,并非所有服务器都使用https.将其部署到未在IIS中设置https绑定的服务器会导致其失败.如果在IIS中没有设置https绑定,是否有办法在web.config中默认使用这两种绑定而不会死亡?
我们已经找到了解决此问题的可能方案,但它并不能很好地满足我们的部署要求.
之前有没有其他人遇到这样的事情,你是怎么解决的?
当我尝试调用WCF服务时,我收到以下消息"验证邮件的安全性时出错".
当我删除自定义验证时,服务没有问题.虽然我在web.config中配置错误,但我无法弄清楚.任何见解将不胜感激.
<system.serviceModel>
<services>
<service behaviorConfiguration="NAThriveExtensions.nableAPIBehavior"
name="NAThriveExtensions.nableAPI">
<endpoint
address=""
binding="basicHttpBinding"
bindingConfiguration="basicHttpBinding_Secure"
contract="NAThriveExtensions.InableAPI">
</endpoint>
<endpoint
address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="NAThriveExtensions.nableAPIBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceCredentials>
<userNameAuthentication
userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType= "NAThriveExtensions.Authentication, NAThriveExtensions" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding_Secure">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud) 有没有办法获得WCF连接的远程IP地址?
我想它没有内置到WCF框架中的原因是WCF可以使用非TCP/IP绑定,因此IP地址并不总是有意义的.
但是,这些信息对于所有广泛使用的绑定都是有意义的(据我所知:BasicHttp,DualHttp,WSHttp和NetTcp).
IP地址可能是使用反射访问的,但我宁愿找到一种记录的方法来获取它而不是入侵框架类.
我已经在Google上搜索了这个问题,似乎很多人在没有找到合适的解决方案的情况下遇到过这种情况(通常的答案是依赖于邮件头,但这意味着信任客户端提供其真实的IP地址,如果您出于安全原因要记录IP地址,则不能选择此选项)
我创建了我的第一个自托管WCF服务.我在C#控制台应用程序中托管它,但它抛出一个错误:
System.ServiceModel.AddressAccessDeniedException:HTTP无法注册URL http:8080
当我以管理员身份运行Visual Studio 2013时,它运行良好,但如果不运行则不行.那么有什么方法可以自动完成它而不是将VS作为ADMIN启动?
到目前为止,我创建了一个HelloService类库,在其中我添加了一个WCF服务,该服务由一个接口IHelloService和HelloService.
IHelloService:
namespace HelloService
{
[ServiceContract]
public interface IHelloService
{
[OperationContract]
String GetMsg();
}
}
Run Code Online (Sandbox Code Playgroud)
HelloService:
namespace HelloService
{
public class HelloService : IHelloService
{
public String GetMsg()
{
return "Service Accessed";
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后我创建了一个C#控制台应用程序HelloServiceHost,它有一个app.config文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors >
<behavior name="MexBehaviour">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="HelloService.HelloService"
behaviorConfiguration="MexBehaviour" >
<endpoint
address="HelloService"
binding="basicHttpBinding"
contract="HelloService.IHelloService"></endpoint>
<endpoint …Run Code Online (Sandbox Code Playgroud) 我正在开发一个WCF服务,该服务将由我不开发的客户端使用,而且它不是.NET(可能是Java).
在任何情况下,该服务都应支持相互SSL身份验证,其中服务和客户端都在传输层使用证书X.509证书进行身份验证.证书已在之前的各方之间进行了交换.
我的问题是我似乎无法获得正确的WCF配置,以便客户端证书身份验证正常工作.我期望的是,作为TLS握手的一部分,服务器还包括一个Certificate Request,如下所示:

在此之后,客户应该回答"证书验证"等问题:

(最新)服务配置就是这个.我正在使用自定义绑定,身份验证模式设置为MutualSslNegotiated.
<bindings>
<customBinding>
<binding name="CarShareSecureHttpBindingCustom">
<textMessageEncoding messageVersion="Soap11" />
<security authenticationMode="MutualSslNegotiated"/>
<httpsTransport requireClientCertificate="true" />
</binding>
</customBinding>
</bindings>
...
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" httpHelpPageEnabled="false" />
<serviceCredentials>
<serviceCertificate findValue="..." storeLocation="LocalMachine" x509FindType="FindByIssuerName" storeName="My" />
<clientCertificate>
<certificate findValue="..." storeName="My" storeLocation="LocalMachine" x509FindType="FindByIssuerName"/>
</clientCertificate>
</serviceCredentials>
</behavior>
</serviceBehaviors>
Run Code Online (Sandbox Code Playgroud)
对于我尝试过的所有服务配置,握手的Server Hello部分都是这样的,没有CertificateRequest.

其他我应该提到的事情:
basicHttpBinding和a wsHttpBidning安全模式设置为Transport和客户端身份验证设置为Certificate,没有结果(实际上是相同的结果).任何想法,将不胜感激.
我正在尝试使用带有消息合同的WCF流,因为我需要在流本身旁边添加其他参数.
基本上我正在创建一个文件上传和下载服务,顶部还有一些额外的逻辑.
不幸的是,当我尝试从浏览器点击服务以检查一切正常时,我收到以下错误:
'/'应用程序中的服务器错误.合同'IFileTransferService'中的"UploadFile"操作使用具有SOAP头的MessageContract.None MessageVersion不支持SOAP标头.
不幸的是谷歌搜索它并没有产生任何帮助我的重要结果.你们能帮助我吗?这里是服务的细节(我已经删除了下载部分,因为空间的原因).
[ServiceContract(Namespace = "http://www.acme.org/2009/04")]
public interface IFileTransferService
{
[OperationContract(Action = "UploadFile")]
void UploadFile(FileUploadMessage request);
}
[MessageContract]
public class FileUploadMessage
{
[MessageHeader(MustUnderstand = true)]
public FileMetaData Metadata { get; set; }
[MessageBodyMember(Order = 1)]
public Stream FileByteStream { get; set; }
}
[DataContract(Namespace = "http://schemas.acme.org/2009/04")]
public class FileMetaData
{
[DataMember(Name="FileType", Order=0, IsRequired=true)]
public FileTypeEnum fileType;
[DataMember(Name="localFilename", Order=1, IsRequired=false)]
public string localFileName;
[DataMember(Name = "remoteFilename", Order = 2, IsRequired = false)]
public string remoteFileName;
}
Run Code Online (Sandbox Code Playgroud)
我试图使用basichttpbinding和customhttp绑定,但效果不佳:
<customBinding> …Run Code Online (Sandbox Code Playgroud) 在WCF端点元素中bindingConfiguration和bindingName元素之间究竟有什么区别?我问的原因是我正在创建一个使用basicHttpBinding和SSL的端点.我像这样配置了web.config:
<basicHttpBinding>
<binding name="basicHttps">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
Run Code Online (Sandbox Code Playgroud)
<endpoint binding="basicHttpBinding" bindingConfiguration="basicHttps" contract="Hsp.Services.Interface.Catalog.ICatalogService" address="" />
Run Code Online (Sandbox Code Playgroud)
但是,使用bindingConfiguration时,https无法正常工作.当我将bindingConfiguration更改为bindingName时,它按预期工作.那么,这两者究竟有什么区别?
我在WCF中创建了一个Web服务,它返回超过54000个数据行,每行有10个数据.我使用wsHttpBinding进行通信.该服务适用于较少的数据(即2000行)但在尝试发送50000+行(~2MB)的大型记录集时会爆炸.异常消息是这样的
收到HTTP响应时发生错误
http://localhost:9002/MyService.svc.这可能是由于服务端点绑定不使用HTTP协议.这也可能是由于服务器中止HTTP请求上下文(可能是由于服务关闭).请参阅服务器日志以获取更多详
请不要告诉我在客户端使用分页 - 我知道它会解决问题.但我需要客户端的整个数据块.
我在服务器上的服务配置是
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="MyWsHttpBinding" />
</wsHttpBinding>
</bindings>
<services>
<service name="AdminService">
<endpoint address="AdminSrv"
binding="wsHttpBinding"
contract="IAdminService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="/Bus/IRfotoWCF" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to …Run Code Online (Sandbox Code Playgroud) 是否可以仅使用BasicHttpBinding绑定在IIS中使用SSL和基本身份验证设置WCF服务?(我不能使用wsHttpBinding绑定)
该站点托管在IIS 7上,并设置了以下身份验证:
- Anonymous access: off
- Basic authentication: on
- Integrated Windows authentication: off !!
Run Code Online (Sandbox Code Playgroud)
服务配置:
<services>
<service name="NameSpace.SomeService">
<host>
<baseAddresses>
<add baseAddress="https://hostname/SomeService/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<endpoint address="" binding="basicHttpBinding"
bindingNamespace="http://hostname/SomeMethodName/1"
contract="NameSpace.ISomeInterfaceService"
name="Default"
/>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging …Run Code Online (Sandbox Code Playgroud) wcf ×10
wcf-binding ×10
ssl ×3
.net ×2
c# ×2
wcf-security ×2
web-config ×2
asp.net ×1
https ×1
iis ×1
self-hosting ×1