如何通过TCP端口托管WCF服务,如何通过这些TCP端口监听和使用服务?
也就是说,除了net.tcp绑定之外,是否有某种方法可以使用TCP端口进行托管和使用?
我有一组IIS7托管的net.tcp WCF服务,它们为我的ASP.NET MVC Web应用程序提供服务.Web应用程序可通过Internet访问.
WCF Services (IIS7) <--> ASP.NET MVC Application <--> Client Browser
这些服务是用户名验证的,客户端(我的Web应用程序)用于登录的帐户最终作为主机上的当前主体.
我希望其中一个服务的身份验证方式不同,因为它为我的登录视图提供了视图模型.当它被调用时,客户端显然还没有登录.我认为,如果服务托管在与Web应用程序不在同一域中的计算机上,则Windows身份验证可以提供最佳或可能只是基于证书的安全性(实际上我也应该用于经过身份验证的服务).
但这不是重点.使用多个TCP绑定是给我带来麻烦的.我在我的客户端配置中尝试将其设置为:
<bindings>
<netTcpBinding>
<binding>
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName"/>
</security>
</binding>
<binding name="public">
<security mode="Transport">
<message clientCredentialType="Windows"/>
</security>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint contract="Server.IService1" binding="netTcpBinding" address="net.tcp://localhost:8081/Service1.svc"/>
<endpoint contract="Server.IService2" binding="netTcpBinding" bindingConfiguration="public" address="net.tcp://localhost:8081/Service2.svc"/>
</client>
Run Code Online (Sandbox Code Playgroud)
服务器配置如下:
<bindings>
<netTcpBinding>
<binding portSharingEnabled="true">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName"/>
</security>
</binding>
<binding name="public">
<security mode="Transport">
<message clientCredentialType="Windows"/>
</security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="Service1">
<endpoint contract="Server.IService1, Library" binding="netTcpBinding" address=""/>
</service>
<service name="Service2">
<endpoint …Run Code Online (Sandbox Code Playgroud) 我想在单个服务中使用wshttpbinding(使用SSL而不使用SSL),但它不起作用,任何人都实现了它.那么请指导我如何实现这一目标?
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="CommonBehaviour">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<serviceCredentials>
<serviceCertificate findValue="AzilenTechnology" x509FindType="FindBySubjectName" />
</serviceCredentials>
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBindingConfig" closeTimeout="00:10:00"
openTimeout="00:10:00" sendTimeout="00:10:00" maxBufferSize="2147483647"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Mtom">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="wsHttpBindingConfig" closeTimeout="00:10:00" openTimeout="00:10:00"
sendTimeout="00:10:00" bypassProxyOnLocal="true" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" messageEncoding="Mtom">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="CommonBehaviour" name="wcfAllInOne.wcfFileIO">
<endpoint binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange" />
<endpoint address="http://localhost:82/WCFAllInOne/wcfFileIO.svc/basicHttpEndPoint" binding="basicHttpBinding" …Run Code Online (Sandbox Code Playgroud) 我在服务器配置文件中指定了maxItemsInObjectGraph,但在创建客户端配置文件时,此属性被忽略,我必须手动将其添加到endpointBehaviors部分.
有没有办法我可以在配置文件中进行一些更改,以便每次我通过Svcutil.exe生成客户端配置和代理时,此行为自动包含在客户端配置文件中?
我尝试[ServiceBehavior(MaxItemsInObjectGraph = 2147483647)]了服务接口,但它给我一个错误说Attribute 'ServiceBehavior' is not valid on this declaration type. It is only valid on 'class' declarations.
我有一个N-Tier应用程序,其构建如下:
在IIS7的服务器端坐着一个ASP.Net应用程序,它公开WCF服务上的方法.这些方法使用EF4与DB通信.用Silverlight 4.0编写的客户端正在调用WCF服务上的方法.
WCF服务公开此方法:
[OperationContract]
void DeleteItem(int i_ItemId);
Run Code Online (Sandbox Code Playgroud)
我不熟悉WCF服务,但我认为接下来的观察结果是正确的(如果我错了,请纠正我):
1)如果我按原样保留此方法/服务,任何知道我的服务位于http://www.mysite.com/myservice.svc的人都可以打开VisualStudio,打开"添加服务参考"并开始拨打电话到DeleteItem().
2)如果我尝试通过删除MEX端点来解决上述问题,仍然可以使用一些手动编码来调用服务.
因此,我试图解决这两个问题,开始学习WCF中的一些内置安全功能.快速浏览后,我想我可以使用以下绑定配置,以便拨打服务时需要用户名和密码:
<wsHttpBinding>
<binding name="RequestUserName" >
<security mode="Message">
<message clientCredentialType="UserName"/>
</security>
</binding>
Run Code Online (Sandbox Code Playgroud)
试图采用这种解决方案,我首先想到的是:当用户登录客户端时,客户端使用用户的名称和密码作为WCF调用的凭据.在服务器端,这些凭据将根据数据库进行验证.
现在的问题是,用户已知这些凭证(用户名和密码),因此他可以使用它们以我已经提到的方式调用DeleteItem().
从这里我想出了两个解决方案:
1)使用userName和password作为凭证,我将在客户端使用硬编码密钥.在XAP中加扰Dll可能会阻止某人获取此密钥.
2)当用户登录客户端时,服务器会发送某种临时令牌(GUID或其他内容),客户端可以使用该临时令牌在此通信会话期间对其进行身份验证(比方说,直到用户关闭客户端) .
我的问题是:
第一个解决方案提供的安全级别以及为了破解它而需要努力的程度是多少?
如果第一个解决方案非常容易破解,那么在WCF中是否有内置的方法来管理我在第二个解决方案中提到的令牌系统?
欢迎其他可以达到范围的解决方案.
我正在尝试在两个进程之间(在同一个盒子上)配置服务器上的net.pipe绑定.我在Windows 7中本地工作,但在生产服务器(Windows Server 2008 R2)上,它无法正常工作.
我可以证实我有:
这就是我的开发机器所需的全部内容.还有什么我需要做的吗?
我得到的错误来自一个简单的控制台应用程序测试客户端:
未处理的异常:System.ServiceModel.EndpointNotFoundException:net.pipe://nameOfService.svc上没有可以接受该消息的端点.这通常是由错误的地址或SOAP操作引起的.有关更多详细信息,请参阅InnerException(如果存在).---> System.IO.PipeException:在本地计算机上找不到管道端点'net.pipe://nameOfService.svc'.
这里有一些配置:
客户:
<system.serviceModel>
<bindings>
<netNamedPipeBinding>
<binding name="NetNamedPipeBinding_IWebAppNotifyService">
<security mode="None" />
</binding>
</netNamedPipeBinding>
</bindings>
<client>
<endpoint address="net.pipe://nameOfService.svc"
binding="netNamedPipeBinding" bindingConfiguration="NetNamedPipeBinding_IWebAppNotifyService"
contract="ServiceReference2.IWebAppNotifyService" name="NetNamedPipeBinding_IWebAppNotifyService" />
</client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
服务器:
<bindings>
<netNamedPipeBinding>
<binding name="WebAppNotifyServiceBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
</security>
</binding>
<binding name="ScannerManagerCommandBinding">
<security mode="None" />
</binding>
</netNamedPipeBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="WebAppNotifyServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="True" /> …Run Code Online (Sandbox Code Playgroud) 如何将WCF customBinding设置为仅使用传输级安全性?
如果它是一个wsHttpBinding,它将是:
<security mode="Transport" />
Run Code Online (Sandbox Code Playgroud)
场景是我正在调用一个使用仅传输安全性的Java SOAP服务.没有消息签名.
我们正计划实施我们的新软件应用程序,如下所示.
这种架构是否适合用途?
需要注意的事项:
我们还考虑了什么?
我们尝试过WCF NetPeerTcpBinding(即P2P),但它不支持请求 - 回复操作.
我们已经尝试过WCF Duplex,但是在要注意的项目中列出了上面列出的要求,我们最终会在两端都有一个客户端和服务器.

我有一个WCF服务,它将客户保存到数据库,并在Internet Explorer中按预期工作,但不在 Chrome中工作(因此我会遗漏HTML/Json,因为它让我觉得这是一个Web配置问题,但我可以发布如果有人喜欢).
在Chrome中我收到错误:
无法加载资源:服务器响应状态为405(方法不允许)Subscriber.htm:1 XMLHttpRequest无法加载http://example.com/MyService.svc/SaveCustomer.无效的HTTP状态代码405
我的网站配置:
<system.web>
<compilation debug="false" strict="false" explicit="true" targetFramework="4.0" />
<pages>
<namespaces>
<add namespace="System.Runtime.Serialization" />
<add namespace="System.ServiceModel" />
<add namespace="System.ServiceModel.Web" />
</namespaces>
</pages>
</system.web>
<system.serviceModel>
<services>
<service name="IService.MyService">
<endpoint address="http://example.com/MyService.svc"
binding="webHttpBinding"
bindingConfiguration=""
contract="IService"
behaviorConfiguration="webHttpBinding" />
</service>
</services>
<client>
<endpoint
binding="webHttpBinding"
bindingConfiguration=""
address="http://example.com/MyService.svc"
contract="IService" />
</client>
<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"/> …Run Code Online (Sandbox Code Playgroud) IIS中托管的WCF服务的绑定和客户端端点如下所示.
<bindings>
<customBinding>
<binding name="notSecureBinding">
<binaryMessageEncoding />
<httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</binding>
<binding name="SecureBinding">
<binaryMessageEncoding />
<httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://ServerName.myDomain.org/ADSearcher/Service1.svc"
binding="customBinding"
bindingConfiguration="notSecureBinding"
contract="GetData.GetData"
name="notSecureBinding" />
<endpoint address="https://ServerName.myDomain.org/ADSearcher/Service1.svc"
binding="customBinding"
bindingConfiguration="SecureBinding"
contract="GetData.GetData"
name="SecureBinding" />
</client>
Run Code Online (Sandbox Code Playgroud)
现在我想做的是连接到这个服务并读取我想要的数据,而不是在我的asp.net mvc 4应用程序中添加任何服务引用.
我在下面尝试了这段代码
BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
EndpointAddress endpointAddress = new EndpointAddress("http://ServerName.myDomain.org/ADSearcher/Service1.svc");
IService1 ADUser = new ChannelFactory<IService1>(basicHttpBinding, endpointAddress).CreateChannel();
DataTable ADUserInfo = ADUser.GetADUserList(strUserName, strFirstName, strLastName, strEmail, domain);
Run Code Online (Sandbox Code Playgroud)
但上面的代码抛出了下面的错误.
由于EndpointDispatcher上的ContractFilter不匹配,因此无法在接收方处理带有Action'http://tempuri.org/IService1/GetADUserList ' 的消息.这可能是由于合同不匹配(发送方与接收方之间的操作不匹配)或发送方与接收方之间的绑定/安全性不匹配.检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息,传输,无).
它看起来像绑定不匹配,因为在WCF配置中,我使用"customBinding"但我无法在C#代码中定义它,只找到"BasicHttpBinding".
有没有人知道我如何通过C#代码成功连接到这个IIS托管的WCF服务并调用我的"GetADUserList"方法而不向我的MVC应用程序添加服务引用?
wcf-binding ×10
wcf ×9
wcf-security ×3
.net ×2
c# ×2
.net-4.0 ×1
architecture ×1
asp.net-mvc ×1
net.pipe ×1
net.tcp ×1
tcp ×1