我遇到了一个问题.我在WCF有点新,所以任何帮助都会有很大的帮助.
这是我的代码:
public static void StartHosts()
{
try
{
// Create a new host
ServiceHost host = new ServiceHost(typeof(ServerTasks));
List<IPAddress> ips = new List<IPAddress>(Dns.GetHostAddresses(Dns.GetHostName()));
if (IPAddress.Loopback != null)
ips.Add(IPAddress.Loopback);
ips.RemoveAll(i => i.AddressFamily != AddressFamily.InterNetwork);
foreach (var ip in ips)
{
string uri = string.Empty;
// Formulate the uri for this host
uri = string.Format(
"net.tcp://{0}:{1}/ServerTasks",
ip.ToString(),
ServerSettings.Instance.TCPListeningPort
);
// Add the endpoint binding
host.AddServiceEndpoint(
typeof(ServerTasks),
new NetTcpBinding(SecurityMode.Transport) { TransferMode = TransferMode.Streamed },
uri
);
}
// Add the meta data …Run Code Online (Sandbox Code Playgroud) 我有一组服务合同,将我的服务接口分成相关功能块.我目前正在使用单个服务类实现所有合同(可能希望稍后拆分它们,但现在单个服务类就足够了).
我试图使用配置文件配置端点(而不是通过代码).问题是我得到了一个,ServiceActivationException因为两个端点(每个服务合同一个)正在尝试监听同一个uri.异常细节说,要实现这一点,两个端点必须共享绑定对象,这是有道理但我无法弄清楚如何通过配置这样做(我没有尝试通过代码,因为我在IIS托管,但但我可以想象这是一个在代码中配置的简单练习.
以下是我目前正在使用的配置(这仍然是开发人员,因此我目前不担心其中一些设置可能会暴露的安全问题等):
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service name="CDC.WebPortal.MidTier.MidTierAccessService"
behaviorConfiguration="MidTierServiceBehaviour" >
<endpoint address=""
binding="webHttpBinding"
bindingConfiguration="RestBindingConfiguration"
contract="****************************.IProductService" />
<endpoint address=""
binding="webHttpBinding"
bindingConfiguration="RestBindingConfiguration"
contract="****************************.ICategoryService" />
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="RestBindingConfiguration"
maxReceivedMessageSize="104857600">
<readerQuotas maxStringContentLength="104857600"/>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="MidTierServiceBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
Run Code Online (Sandbox Code Playgroud)
所以我的问题是如何在两个端点之间共享这种绑定?
在这个SO问题中的评论表明我可能无法做到这一点,但我不相信这是正确的.
更新1根据这篇MS出版物,我正在做的应该没问题......
UPDATE2如果有帮助,这是svc文件内容:
<%@ ServiceHost Language="VB" Debug="true"
Service="*********************.MidTierAccessService"
Factory="Microsoft.ServiceModel.Web.WebServiceHost2Factory" %>
Run Code Online (Sandbox Code Playgroud)
更新3这是例外细节:
绑定实例已与侦听URI"********************"相关联.如果两个端点想要共享相同的ListenUri,则它们还必须共享相同的绑定对象实例.两个冲突的端点要么在AddServiceEndpoint()调用中,在配置文件中指定,要么在AddServiceEndpoint()和config的组合中指定.
更新4好的我以前错过了这个,说明"在为特定的.svc服务公开多个端点时,您将需要使用相对地址".造成这种情况的原因与IIS虚拟目录确定服务的基地址有关,任何人都可以更详细地解释这一点,即为什么IIS需要为每个合同进行相对寻址.
在参考我之前的问题时,我想知道如何从客户端应用程序中提取WCF服务的信息,以了解如果服务只公开一个使用webHttpBinding的端点,那么会暴露哪些方法/类型?
总而言之,在我之前的问题中,我开始知道使用webHttpBinding的端点不会在生成的WSDL中暴露,因为它将是一个JSON端点并且只是不兼容.
我遇到以下错误的问题:" 已超出传入邮件的最大邮件大小配额(65536).要增加配额,请在相应的绑定元素上使用MaxReceivedMessageSize属性. "
所以我做了一些研究,发现我需要增加缓冲区和消息大小,这是我的WCF服务配置文件:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="default" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"/>
</wsHttpBinding>
</bindings>
<services>
<service name="WCF.Service.Service">
<endpoint address="ws" name="ws" bindingConfiguration="default" binding="wsHttpBinding" contract="WCF.Service.Contracts.IService" />
<endpoint address="mex" binding="mexHttpBinding" name="mex" 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 httpGetEnabled="True" />
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to …Run Code Online (Sandbox Code Playgroud) 我正在使用C#3.5和Visual Studio 2010中的WCF服务开发Winforms客户端应用程序.
每次我在IDE中使用" 更新服务引用 "时,考虑到我已经有一个工作绑定app.config,会生成一个具有相同名称和尾随"1"的附加绑定条目.
我在客户端的app.config是:
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IIssueTracker" closeTimeout="00:01:00"...
Run Code Online (Sandbox Code Playgroud)
在"更新服务参考"之后,我有:
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IIssueTracker" closeTimeout="00:01:00"...
<binding name="WSHttpBinding_IIssueTracker1" closeTimeout="00:01:00"...
Run Code Online (Sandbox Code Playgroud)
所以我需要一直删除这个未使用的绑定.
这让我疯狂.有没有办法禁用这种行为?
我搜索了一个简单的类或一组函数来编码和解码内容类型'application/soap + msbin1'
我的最终目标是能够使用HttpWebRequest和HttpWebResponse与运行silverlight应用程序的Web服务器进行交互.
以上两个项目中的任何一个的任何样品或实例都非常感谢.
在这里,我在浏览器中从托管的RESTful服务调用该方法
https://eshop/LinkService/LinkService.svc/GetStudentObj
Run Code Online (Sandbox Code Playgroud)
并得到以下错误
The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None)
Run Code Online (Sandbox Code Playgroud)
配置文件
<system.serviceModel>
<services>
<service name="LinkService.LinkService" behaviorConfiguration="MyServiceBehavior">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="https" contract="LinkService.ILinkService" />
<endpoint …Run Code Online (Sandbox Code Playgroud) 我的解决方案中有3个项目.第一个项目是asp.net mvc(作为客户端应用程序),另一个是WCF service application最后一个项目workflow activity library.我添加了WCF服务引用到工作流项目和工作流项目引用添加到asp.net mvc.当我在活动中使用wcf服务并从asp.net mvc启动工作流时,我收到此错误:
无法在ServiceModel客户端配置部分中找到名称为BasicHttpBinding_IService和合同IService的端点元素.这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此名称匹配的端点元素.
这是我的工作流活动库app.config文件内容:
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:30717/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="Service1.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)
这是我的wcf项目web.config文件内容:
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpBinding" scheme="http" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/> …Run Code Online (Sandbox Code Playgroud) 我正在尝试在WCF服务中使用二进制消息编码,遵循此站点上的许多示例.
在服务器上,我将绑定声明为:
<customBinding>
<binding name="binaryHttpBinding">
<binaryMessageEncoding maxReadPoolSize="4096000" maxSessionSize="4096000" maxWritePoolSize="4096000">
<readerQuotas maxDepth="32" maxStringContentLength="4096000"
maxArrayLength="4096000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binaryMessageEncoding>
<httpTransport maxBufferPoolSize="4096000" maxBufferSize="4096000" maxReceivedMessageSize="4096000"/>
</binding>
</customBinding>
Run Code Online (Sandbox Code Playgroud)
该服务设置为使用它(我认为):
<service behaviorConfiguration="MyService.ServiceBehavior" name="MyService.ContentUploadService">
<endpoint
address=""
binding="customBinding"
bindingConfiguration="binaryHttpBinding"
contract="MyService.IContentUpload"
name="MyService.ContentUploadService" />
Run Code Online (Sandbox Code Playgroud)
客户端具有相同的声明:
<customBinding>
<binding name="binaryHttpBinding">
<binaryMessageEncoding maxReadPoolSize="4096000" maxSessionSize="4096000" maxWritePoolSize="4096000">
<readerQuotas maxDepth="32" maxStringContentLength="4096000"
maxArrayLength="4096000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binaryMessageEncoding>
<httpTransport maxBufferPoolSize="4096000" maxBufferSize="4096000" maxReceivedMessageSize="4096000"/>
</binding>
</customBinding>
Run Code Online (Sandbox Code Playgroud)
和:
<endpoint
address="http://foo.com/ContentUploadService.svc"
binding="customBinding"
bindingConfiguration="binaryHttpBinding"
contract="MyService.IContentUpload"
name="MyService.ContentUploadService"/>
Run Code Online (Sandbox Code Playgroud)
客户端似乎正在工作,但服务器抛出一个异常,表明绑定不到位:
内容类型application/soap + msbin1被发送到期望text/xml的服务; 字符集= UTF-8.客户端和服务绑定可能不匹配.
在日志文件中出现此错误之前,就会在尝试打开服务主机时抛出此错误,这必须是原因.
找不到配置评估上下文.
我为此消息尝试的搜索链接都没有帮助.那么,我错过了什么基本文章?
我有一个远程WCF Web服务,我从我的应用程序连接到.
应用程序可能在具有多个IP地址(或多个物理网络接口)的服务器上运行
我需要确保我可以控制哪个IP地址用于出站请求,而不是仅按照常规度量规则使用"首选"接口.
这样做的原因是软件的多个副本将在同一台机器上运行,每个副本都绑定到一个特定的IP地址用于自己的操作,并且连接的远程服务需要知道哪个正在用于连接回来它在以后的时间(因为地址错误意味着连接到错误的服务)
使用传统的ASMX服务,可以通过覆盖GetWebRequest(Uri uri)为服务生成的分部类来完成.但我无法弄清楚如何使用WCF做到这一点.
在一篇不相关的SO帖子中,MVP @JohnSaunders建议通过接管WCF使用的整个传输机制来实现这一点.但我还没弄清楚如何做到这一点.
wcf ×10
wcf-binding ×10
c# ×4
.net ×2
app-config ×1
asp.net ×1
c#-4.0 ×1
iis ×1
iis-7 ×1
iis-7.5 ×1
net.tcp ×1
soap ×1
wcf-client ×1