我正在使用WCF在C#中编写客户端/服务器应用程序.我的所有测试都没问题,但是一旦我部署了服务,我发现与服务器通信时出现了随机问题.我启用了调试并在服务器中看到了这样的消息:
The communication object, System.ServiceModel.Channels.ServerReliableDuplexSessionChannel, cannot be used for communication because it has been Aborted.
Run Code Online (Sandbox Code Playgroud)
模式是这样的:
应用程序如下所示:服务实例提供了与数据库交互的API方法,其类型为"netTcpBinding".几个客户端(大约40个)连接并从服务中随机调用方法.即使没有发送或接收任何东西,客户也可以保持开放几天.
以下是相关位:
服务:
[ServiceContract(CallbackContract = typeof(ISVCCallback), SessionMode = SessionMode.Required)]
[ExceptionMarshallingBehavior]
...
Run Code Online (Sandbox Code Playgroud)
和
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext=true)]
public class SVCService : ISVC
...
Run Code Online (Sandbox Code Playgroud)
服务配置:
<behaviors>
<serviceBehaviors>
<behavior name="behaviorConfig">
<serviceMetadata httpGetEnabled="false" httpGetUrl="" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceThrottling maxConcurrentCalls="50" maxConcurrentSessions="1000"
maxConcurrentInstances="50" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="tcpBinding" closeTimeout="00:01:00" openTimeout="00:10:00"
receiveTimeout="23:59:59" sendTimeout="00:01:30" transferMode="Buffered"
listenBacklog="1000" …Run Code Online (Sandbox Code Playgroud) 如何在调用WCF服务时定义WCF客户端使用的LocalEndPoint(如果客户端计算机有多个IP地址)?
我有一台位于DMZ中的机器有两个IP地址,外部IP地址可以通过防火墙通过我们位于外部服务提供商的网络服务器的VPN连接到达.在此计算机上运行基于WCF和Unity的自定义应用程序服务器,该服务器应充当代理或应用程序级网关(ALG).它应接受来自Web服务器的服务调用,并使用wcf客户端工厂重新生成服务调用,将它们转发到LAN中的真实应用服务器.
当使用wcf客户端工厂在此代理上重新创建服务调用时,wcf客户端应使用此计算机的第二个内部IP地址,因为只允许来自此内部IP地址的消息通过防火墙才能到达局域网中的应用服务器.不幸的是,我们的wcf客户端代理始终选择使用第一个"外部"IP地址创建传出消息.我正在寻找一种方法来明确设置wcf客户端代理使用的IP地址.
我只能找到一个允许定义LocalEndPoint或ClientBaseAddress的WCF绑定元素:CompositeDuplexBindingElement.据我所知,这个属性是告诉服务器在哪里发送asynch回复消息,所以它与我正在寻找的设置不同.
任何想法我能做些什么才能找到可行的解决方案?
提前感谢任何有用的建议!!
这似乎是一个类似的问题,只使用TcpClient/Sockets而不是WCF: 在C#中指定用于TCPClient/Socket的传出IP地址
另一个,这次是关于SoapClient: 在发送传出请求之前将新的SoapClient绑定到特定的IP地址
当尝试使用SVCUTIL.EXE(在命令行或通过Visual Studio)创建Web服务代理(WCF )时,我得到以下无意义的错误消息.
注意:该服务没有任何问题,因为它可以在另一台机器上正常工作.这是Windows的新安装,该服务在我的本地盒子上.使用不同机器上的URL在我的机器上生成相同的代理工作正常.
这是怎么回事?!
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 4.0.30319.1]
Copyright (c) Microsoft Corporation. All rights reserved.
Attempting to download metadata from 'https://ws1.example.com/ShoppingCartWS/WCF/ShoppingCartWCF.svc?wsdl' using WS-Metadata Exchan
Error: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageCont
Error: Schema with target namespace '' could not be found.
XPath to Error Source: //wsdl:definitions[@targetNamespace='']/wsdl:portType[@name='IShoppingCart']
Error: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType …Run Code Online (Sandbox Code Playgroud) 与讨论该主题的所有SO帖子相比,我对在a中包装流对象不感兴趣[MessageContract],因为在流模式(afaik)中不允许这样做.
当我处于流模式时,如何向客户端返回一些元数据,例如长度和文件名?我可以添加WCF/SOAP标头吗?我该怎么做?
我正在寻找扩展文件流类并添加一个[MessageHeader]属性,但我无法让它工作.
我正在使用DataContract和DataMember属性装饰WCF中的一个简单对象.我有一个List<T>属性,并故意设计它在第一次访问时实例化支持字段(如果为null).该类的缩写版本如下.
[DataContract]
public class FieldSetData
{
private List<FormFieldData> _formFields;
[DataMember]
public List<FormFieldData> FormFields
{
get
{
if (this._formFields == null)
{
this._formFields = new List<FormFieldData>();
}
return this._formFields;
}
set
{
this._formFields = value;
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,在生成的客户端/代理类上,我无法在第一次手动实例化时访问该属性,因为它是null(这是if上面的逻辑应该处理的).
下面的第二行代码返回null:
//proxy class version
FieldSetData data = new FieldSetData();
data.FormFields.Add(new FormFieldData()); //FormFields property is null
Run Code Online (Sandbox Code Playgroud)
我必须这样做:
//instantiate the List<T> property
FieldSetData data = new FieldSetData { FormFields = new List<FormFieldData>() };
data.FormFields.Add(new FormFieldData());
Run Code Online (Sandbox Code Playgroud)
我对WCF很新,所以也许我在这里遗漏了一些东西?我认为代理类生成会尊重属性中的 …
我知道我可以通过代码使用来做到这一点
myClient.ClientCredentials.UserName.UserName = "User";
myClient.ClientCredentials.UserName.Password = "Password";
Run Code Online (Sandbox Code Playgroud)
是否可以通过配置为客户端提供相同的功能?
我正在寻找使用.net 4 wcf服务进行动态路由的示例.请帮我.
我在一个WCF库中定义了多个服务契约,这些托管在Windows服务下托管.这些服务在Windows服务配置文件中公开如下:
<services>
<service behaviorConfiguration="ReportingComponentLibrary.TemplateServiceBehavior"
name="ReportingComponentLibrary.TemplateService">
<endpoint address="" binding="wsHttpBinding" contract="ReportingComponentLibrary.ITemplateService" bindingConfiguration="wsHttp" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" ></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/ReportingComponentLibrary/TemplateService/" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="ReportingComponentLibrary.TemplateServiceBehavior"
name="ReportingComponentLibrary.TemplateReportService">
<endpoint address="" binding="wsHttpBinding" contract="ReportingComponentLibrary.ITemplateReportService" bindingConfiguration="wsHttp" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" ></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/ReportingComponentLibrary/TemplateReportService/" />
</baseAddresses>
</host>
</service>
</services>
Run Code Online (Sandbox Code Playgroud)
现在,当我在客户端应用程序中添加服务引用时,
是否可以为上述两个服务添加一个服务引用或
我需要为每个服务/服务合同分开参考.
以下是我的申请详情:
我有三个不同的项目:
现在,WCF服务库中的App.Config如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="wsHttp" maxReceivedMessageSize="50000000" maxBufferPoolSize="50000000" messageEncoding="Mtom">
<readerQuotas maxDepth="500" maxStringContentLength="500000000" maxArrayLength="500000000"
maxBytesPerRead="500000000" maxNameTableCharCount="500000000" />
</binding> …Run Code Online (Sandbox Code Playgroud) 我有一个要求,我必须使用System.Object作为WCF中的参数.因为它不可序列化,所以我收到消息,因为它不支持操作,因为它使用System.Object.解决这个问题的任何方法.
要使用配置文件执行上述操作,我会这样做:
<endpoint
address="...."
binding="netTcpBinding"
bindingConfiguration="MyBinding"
contract="IService1">
<identity>
<servicePrincipalName value="name"/>
</identity>
</endpoint>
Run Code Online (Sandbox Code Playgroud)
但是如何将其添加到下面的代码中?
Uri uri = new Uri("http://example.com/service");
ServiceHost host = new ServiceHost(typeof(Service1), uri);
NetTcpBinding binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.Message;
binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
host.AddServiceEndpoint(typeof(IService1), binding, uri);
host.Open();
Run Code Online (Sandbox Code Playgroud) 您能告诉我WCF客户端和非WCF客户端之间有什么区别吗?
当我使用生成SvcUtil工具WCF服务的代理,并把在客户端,是什么创造 - WCF客户端或者非WCF客户端?
我应该何时使用WCF客户端和非WCF客户端?
wcf-client ×12
wcf ×11
.net ×4
c# ×4
wcf-binding ×3
asp.net ×1
filestream ×1
ip-address ×1
properties ×1
streaming ×1
wcf-routing ×1
ws-security ×1