我需要将自定义消息格式化程序应用于服务中的所有操作.
我没有手动将OperationBehavior应用于所有操作,而是试图在ServiceBehavior中循环遍历所有操作(我的序列化程序的细节并不重要,只是它实现了IDispatchMessageFormatter):
public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase) {
foreach (ChannelDispatcher channelDispatcher in serviceHostBase.ChannelDispatchers) {
foreach (EndpointDispatcher endpointDispatcher in channelDispatcher.Endpoints.Where(e => !e.IsSystemEndpoint)) {
foreach (DispatchOperation dispatchOperation in endpointDispatcher.DispatchRuntime.Operations) {
LoggedOperationSerializer serializer = new LoggedOperationSerializer(dispatchOperation.Formatter);
dispatchOperation.Formatter = serializer;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
串行器似乎设置得很好,没有错误.但是,当我设置断点和调试时,永远不会触发LoggedOperationSerializer上的DeserializeRequest方法.
相反,如果我在这样的OperationBehavior中应用格式化程序:
public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation) {
LoggedOperationSerializer serializer = new LoggedOperationSerializer(dispatchOperation.Formatter);
dispatchOperation.Formatter = serializer;
}
Run Code Online (Sandbox Code Playgroud)
然后按预期命中DeserializeRequest方法.
如果我同时应用ServiceBehvior和OperationBehavior并按预期附加调试器,则首先触发显示的第一个代码块,迭代服务上的所有操作,并设置格式化程序.但是,当命中OperationBehavior的ApplyDispatchBehavior时,上面设置的格式化程序已"掉线",并且已被默认的CompositeDispatchFormatter替换.
我真的不想手动将OperationBehavior应用于所有操作以使其工作......任何关于为什么会发生什么的想法?
这是在使用WebHttpBinding的情况下完全相关,我不知道为什么会这样.
我有一个非常简单的wcf应用程序,由App.config,Iservice.cs,Service,cs和Service.svc组成.我只是将其发布到IIS并最终使用我的DLL的bin目录,web.config(从app.config中导出)和我的.svc文件,这是浏览访问服务的内容.
我想将此移至Azure,但我不确定最简单的方法.我在vs2010中创建了一个新的Windows Azure项目但我不能将我现有的项目添加为角色,而是我不得不创建一个新的Web角色或wcf服务角色.
任何人都可以告诉我我必须改变什么来托管我现有的项目?
我需要创建一个具有下载文件功能的WCF服务.此WCF将由Delphi应用程序使用.
问题:将要下载的文件非常大,可能会导致Delphi端的内存问题.到目前为止,我有这个代码:
[OperationContract]
byte[] DownloadFile(string filePath);
Run Code Online (Sandbox Code Playgroud)
但是这段代码会导致客户端应用程序将所有数据保存在内存中,这可能是一个问题.
我已经读过WCF能够传输数据,您可以阅读:如何:启用流式传输
但我对从MSDN中删除的这段代码有疑问:
[OperationContract]
Stream GetStream(string data);
Run Code Online (Sandbox Code Playgroud)
在客户端,我想传递TFileStream给函数.通过使用TFileStream每个字节读取将直接进入磁盘.但函数RETURNS一个流和我想要的东西是不可能的,因为流不会是函数的参数.
如何将文件从WCF服务直接下载到磁盘?
我在我的web.config for WCF中有以下配置.
<serviceMetadata httpGetEnabled="true" />
Run Code Online (Sandbox Code Playgroud)
所以一旦我这样做,我将获得wsdl中的模式位置
<xsd:import schemaLocation="http://mysever/Projectname/Services/myService?xsd=xsd0" namespace="MyServiceHost/Service/01/2011"/>
Run Code Online (Sandbox Code Playgroud)
但我想将其更改为https:// mysever/Projectname/Services/myService?xsd = xsd0.
我无法启用httpsGetEnabled = true,因为我将通过http获取wsdl,但我希望在https中获得服务请求.
我正在使用负载均衡器,其中负载均衡器对Web服务器的流量超过http.
有什么建议?
WCF中是否需要DataContract属性?
我有一个没有用DataContract标记或没有用DataMember标记属性的类。
当我在4台服务器上部署wcf服务时,出4台服务在3台服务器上工作正常,而在1台服务器上失败,并显示消息“类型'类'无法序列化。请考虑用DataContractAttribute属性标记它,并标记要序列化的所有成员使用DataMemberAttribute属性。”
那么,web.config或machine.config或IIS中是否有任何设置可以强制我在代码中使用序列化程序?要么
如果未指定属性,我可以指定使用默认序列化程序吗?
谢谢,克里希纳
如果我发送的参数会导致大量数据被拉出,我会收到以下错误:
在00:01:00之后等待回复时,请求通道超时.增加传递给Request的调用的超时值或增加Binding上的SendTimeout值.分配给此操作的时间可能是较长超时的一部分.
我增加了所有的超时时间.在客户端我有什么需要做的吗?我想知道这是因为我使用的是wcftestclient吗?我需要调整operationTimeout吗?
我的webconfig有以下内容:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="Basic" sendTimeout="12:00:00" receiveTimeout="12:00:00" openTimeout="00:10:00" closeTimeout="00:10:00"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
<readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="8192"/>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="CaseStudyBehavior" name="EDTFS.ADMS.CaseStudyService">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="Basic"
name="Basic"
contract="EDTFS.ADMS.ICaseStudyService" />
<endpoint address="mex"
binding="mexHttpBinding"
name="Metadata"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CaseStudyBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceTimeouts transactionTimeout="24:00:00"/>
<serviceThrottling maxConcurrentCalls="100" maxConcurrentInstances="100" maxConcurrentSessions="100"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud) 假设我们有两个具有以下布局的项目
void Application_Start(System.Object sender, System.EventArgs e)web.config 看起来像这样
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="fooBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="wcf.DemoService"
behaviorConfiguration="fooBehavior">
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
<endpoint address=""
binding="wsHttpBinding"
contract="wcf.IDemoService" />
</service>
</services>
</system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)
所以...现在......某个地方(如上所述,我想到global.asax)我需要注册,当浏览到URI wcf.DemoService得到解决时,对于mex-request,wcf.IDemoService解析读取属性以获得WSDL.
这通常通过.svc在第一行创建文件并放置标题来完成,例如:
<%@ ServiceHost Language="C#" Debug="true" Service="wcf.DemoService" %>
Run Code Online (Sandbox Code Playgroud)
在例如控制台应用程序中
var serviceHost = new ServiceHost(typeof (wcf.DemoService));
serviceHost.Open();
Run Code Online (Sandbox Code Playgroud)
并将其与host元素中的service元素结合以指定URI - 或者使用另一个ctor-overloadServiceHost
但我宁愿去静态注册(或任何 …
使用任务计划程序运行程序时出现以下错误:
HTTP无法注册URL http:// +:4711/myWCFService /.您的进程没有此命名空间的访问权限(有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkId=70353).---> System.Net.HttpListenerException:访问被拒绝
遗憾的是,以管理员身份运行无法解决我的问题.我也尝试用netsh注册http地址,但我仍然遇到同样的错误.
以下是WCF托管环境的问题:
您正在开发一个在后台执行文件备份的应用程序.后台应用程序将托管Windows Communication Foundation(WCF)服务,并且必须在计算机运行后立即处于活动状态.后台应用程序没有用户界面.前端应用程序将使用WCF服务并将提供用户界面.
您需要为WCF服务选择主机环境.您应该选择哪种托管环境?
- A. Microsoft Internet信息服务(IIS)6.0
- B. Windows进程激活服务(WAS)
- C. Windows窗体应用程序
- D. Windows服务
答案是D,但很多文档的WCF MSDN和书籍都支持IIS/WAS而不是Windows服务,因为它们更强大和更有弹性等等.我真的不明白为什么它必须在这里.D背后的原因是什么?
我正忙着创建一个需要ASYNC调用的WCF Web服务.到目前为止我做到了这一点:
public async Task<bool> sendData(Data data) {
bool sent = await Task<bool>.Factory.StartNew(() => {
return someNameSpace.ReceiveData(data);
});
return sent;
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,对dll的调用是否也需要标记为异步?
即.在dll内
public async Task<bool> ReceiveData(Data data) {
// some async code
// some code here
}
Run Code Online (Sandbox Code Playgroud) wcf ×10
c# ×4
.net ×2
async-await ×1
asynchronous ×1
azure ×1
c#-3.0 ×1
delphi ×1
delphi-2010 ×1
hosting ×1
http ×1
iis-7.5 ×1
wcf-binding ×1
web-config ×1