我已经创建了一个类似的EndpointAddress
EndpointAddress address = new EndpointAddress("http://example.com/services/OrderService.svc");
Run Code Online (Sandbox Code Playgroud)
但我无法以编程方式将此行为添加到此端点.
行为如下:
<behaviors>
<endpointBehaviors>
<behavior name="NewBehavior">
<dataContractSerializer maxItemsInObjectGraph="6553600" />
</behavior>
</endpointBehaviors>
</behaviors>
Run Code Online (Sandbox Code Playgroud) 尝试访问我的WCF服务时出现以下错误.
'对象图中可以序列化或反序列化的最大项数为'65536'.更改对象图或增加MaxItemsInObjectGraph配额
做一些研究,看起来我需要做的就是将此设置更新为更高的值.这是我想要做的,但设置似乎没有从配置中读取.我一直得到65536值的相同异常.
我按照本链接中的说明进行操作,但没有运气.
这是我在WCF服务的Web.Config上配置的内容.
<behaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true" httpGetUrl="" />
<serviceDebug includeExceptionDetailInFaults="false" />
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
</behavior>
</serviceBehaviors>
</behaviors>
Run Code Online (Sandbox Code Playgroud)
这是客户端的app.config中的内容:
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior >
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
</behavior>
</endpointBehaviors>
</behaviors>
Run Code Online (Sandbox Code Playgroud)
最后,我在WCF服务本身上有以下属性:
[ServiceBehavior(MaxItemsInObjectGraph = 2147483646, IncludeExceptionDetailInFaults = true)]
Run Code Online (Sandbox Code Playgroud)
尽管上面的配置,我仍然得到一个例外抱怨65536值.为什么应用程序不使用这些设置?是否还需要在某处设置其他内容?
我正在尝试在配置中指定一个已知类型,但我遇到的问题是它派生自Object.我可以通过属性指定已知类型.但在这种情况下,我需要从配置中使其工作.
这是一个例子.以下工作正常:
[ServiceContract]
[ServiceKnownType(typeof(MyData))]
public interface IContract
{
[OperationContract]
void Send(object data);
}
[DataContract]
public class MyData
{
[DataMember]
public string Message { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我删除ServiceKnownType属性并将以下内容放入配置中:
<system.runtime.serialization>
<dataContractSerializer>
<declaredTypes>
<add type="System.Object, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<knownType type="WpfApplication1.MyData, WpfApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</add>
</declaredTypes>
</dataContractSerializer>
</system.runtime.serialization>
Run Code Online (Sandbox Code Playgroud)
我得到一个ConfigurationErrorsException,消息"属性'类型'的值无效.错误是:类型System.Object不能用作config中的声明类型."
无论如何通过配置使这项工作?
我正在开发一个将消耗大量Web服务的Web应用程序(ASP.NET 3.5).我为每个Web服务创建了一个单独的dll项目:这些项目包含服务引用和客户端代码.
但是,调用网站必须在其web.config中包含<system.serviceModel>信息(<bindings>和<client>节点),即使这些信息也在dll的app.config文件中!我已经尝试将serviceclass.dll.config复制到网站的bin目录,但这没有帮助.
有没有办法集中配置WCF客户端?
我有WCF配置问题.我有一个WCF Web服务,我希望能够使用GET参数通过Web浏览器访问(最终在PHP中使用simplexml_load_file()).我的Visual Studio解决方案被设置为一个WCF服务库项目,其中包含一个接口(定义服务的位置),一个类(实现服务的地方,以及一个默认存在的app.config).我也有一个WCF服务项目,包含.svc文件(指向我的类)和web.config.我的服务接口设计如下:
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using RTXEngineLib.externalLibrary;
namespace RTXEngineLib {
[ServiceContract(Name = "RTXEngine", Namespace = "")]
public interface IRTXEngine {
[OperationContract(Name = "GetCountryList"), WebGet(UriTemplate = "/GetCountryList/", ResponseFormat = WebMessageFormat.Xml)]
List<Country> GetCountryList();
[OperationContract(Name = "GetRegions"), WebGet(UriTemplate = "/GetRegions/?countryID={countryID}", ResponseFormat = WebMessageFormat.Xml)]
List<Region> GetRegions(int countryID);
[OperationContract(Name = "GetExchangeAvailability"), WebGet(UriTemplate = "/GetExchangeAvailability/?countryID={countryID}&month={month}&year={year}®ionID={regionID}&resortID={resortID}", ResponseFormat = WebMessageFormat.Xml)]
AvailabilityList GetExchangeAvailability(int countryID, String month, int year, String regionID = "?", String resortID = "");
[OperationContract(Name = "GetResortsForDate"), WebGet(UriTemplate = …Run Code Online (Sandbox Code Playgroud) 我想知道如何在WCF中配置已知类型.例如,我有一个Person类和一个Employee类.该员工类是的sublass 人类.这两个类都标有[DataContract]属性.
我不想硬编码类的已知类型,比如[ServiceKnownType(typeof(Employee))]在Person类中放置一个,以便WCF知道Employee是Person的子类.
现在,我在主机的App.config中添加了以下XML配置:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.serialization>
<dataContractSerializer>
<declaredTypes>
<add type="Person, WCFWithNoLibrary, Version=1.0.0.0,Culture=neutral,PublicKeyToken=null">
<knownType type="Employee, WCFWithNoLibrary, Version=1.0.0.0,Culture=neutral, PublicKeyToken=null" />
</add>
</declaredTypes>
</dataContractSerializer>
</system.runtime.serialization>
<system.serviceModel>
.......
</system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)
我编译它,运行主机,在客户端添加服务引用并添加一些代码并运行客户端.但是发生了错误:
格式化程序在尝试反序列化消息时抛出异常:尝试反序列化参数时出错
http://www.herbertsabanal.net:person.InnerException消息是'第1行位置错误247.元素'http://www.herbertsabanal.net:person'包含'http://www.herbertsabanal.net/Data:Employee'数据协定的 数据.反序列化器不知道映射到此合同的任何类型.将与"Employee"对应的类型添加到已知类型列表中 - 例如,通过使用KnownTypeAttribute属性或将其添加到传递给DataContractSerializer的已知类型列表中.有关更多详细信息,请参阅InnerException.
以下是数据合同:
[DataContract(Namespace="http://www.herbertsabanal.net/Data", Name="Person")]
class Person
{
string _name;
int _age;
[DataMember(Name="Name", Order=0)]
public string Name
{
get { return _name; }
set { _name = value; }
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试跟随初学者的演示视频到MSDN上的WCF页面.
第一个视频或多或少都很好.我现在正走向第二个视频的结尾.我正在使用VS2010/.NET 4.0,而视频似乎使用的是VS2008(我假设是.NET 3.5,但我不记得).
我们刚刚添加了3个端点:一个普通的http,net.tcp和net.pipe.当我现在尝试运行项目时,Web服务无法启动.
System.InvalidOperationException: Cannot load the X.509 certificate identity specified in the configuration.
at System.ServiceModel.Description.ConfigLoader.LoadIdentity(IdentityElement element)
at System.ServiceModel.Description.ConfigLoader.LoadServiceDescription(ServiceHostBase host, ServiceDescription description, ServiceElement serviceElement, Action`1 addBaseAddress)
at System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader, ServiceDescription description, ServiceElement serviceSection)
at System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader, ServiceDescription description, String configurationName)
at System.ServiceModel.ServiceHostBase.ApplyConfiguration()
at System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses)
at System.ServiceModel.ServiceHost.InitializeDescription(Type serviceType, UriSchemeKeyedCollection baseAddresses)
at System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses)
at Microsoft.Tools.SvcHost.ServiceHostHelper.CreateServiceHost(Type type, ServiceKind kind)
at Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo info)
Run Code Online (Sandbox Code Playgroud)
基于我的Google fu,我遇到了这个帖子:"无法加载配置中指定的X.509证书标识"
我真的不想参与证书,因为我还在尝试基础知识,所以我按照该帖子中的建议添加<dns value="localhost" />标签.异常更改:
Please try changing the …Run Code Online (Sandbox Code Playgroud) 我添加了对具有两个端点的WCF服务的引用.在添加服务时,以下内容将添加到Config文件中:
<client>
<endpoint name="ABCServiceV1" address="http://staging.ABCwebservices.com/ABC/Service.svc"
binding="basicHttpBinding" bindingConfiguration="ABCServiceV1"
contract="ABCService.IService" />
<endpoint name="ABCServiceV2" address="http://staging.ABCwebservices.com/ABC/Service.svc/20"
binding="basicHttpBinding" bindingConfiguration="ABCServiceV2"
contract="ABCService.IService1" />
</client>
Run Code Online (Sandbox Code Playgroud)
创建客户端的代码如下:
ABCService.ServiceClient ABCClient = new ServiceClient("ABCServiceV2");
Run Code Online (Sandbox Code Playgroud)
但是,我收到运行时错误 - "找不到名称为'ABCServiceV2'的端点元素,并在ServiceModel客户端配置部分中收缩'ABCService.IService'.这可能是因为找不到您的应用程序的配置文件,或者因为没有匹配此名称的端点元素可以在客户端元素中找到."
如果我使用ABCService.ServiceClient ABCClient = new ServiceClient("ABCServiceV1");然后一切正常.但是当使用ABCServiceV2时,它正在尝试寻找Contract - ABCService.IService - 它应该在什么时候寻找 - ABCService.IService1.
我如何让它寻找正确的合同?
我想为我的WCF项目使用NHibernate启动模块,就像我用于ASP.NET MVC项目一样.Jeffery Palermo概述了我在他的后期ASP.NET MVC HttpModule注册中使用的启动模块.本质上,代码归结为在web.config中添加一个启动模块,如下所示:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="StartupModule" type="Infrastructure.NHibernateModule, Infrastructure, Version=1.0.0.0, Culture=neutral" />
</modules>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
当我尝试使用WCF测试客户端运行服务或使用SoapUI直接对端点运行时,这不起作用.在WCF项目中,我对NHibernate的简单启动机制有哪些选择?
我有一个本地.wsdl文件定义的SOAP服务,我想用它在Visual Studio 2017中生成.NET Core Connected Service.
我ConnectedService.json看起来像这样:
{
"ProviderId": "Microsoft.VisualStudio.ConnectedService.Wcf",
"Version": "15.0.20119.1312",
"ExtendedData": {
"Uri": "C:\\Path\\MyUsername\\LocalRepository\\soap-service.wsdl",
...
},
...
}
Run Code Online (Sandbox Code Playgroud)
问题是,对于访问此源并且不将其本地存储库放在与我完全相同的位置的任何其他人来说,这完全打破了.
我希望引用与项目相关"Uri": "soap-service.wsdl",但是会导致错误:
如何配置ConnectedService.json以便找到相对于.NET项目的本地文件?
wcf ×9
c# ×4
.net ×2
wcf-endpoint ×2
.net-core ×1
asp.net ×1
binding ×1
c#-4.0 ×1
known-types ×1
nhibernate ×1
soap ×1
wcf-binding ×1
wcf-client ×1
wsdl ×1
x509 ×1