【发布时间】:2014-06-02 17:58:28
【问题描述】:
向我的 WPF 应用程序添加自定义 WCF 服务引用时遇到问题。我已经在这项服务和应用程序上工作了将近 6 个月,直到今天才遇到这个问题。每当我尝试通过“添加服务引用”添加 WCF 服务时,我所有返回 List 的方法都试图返回 T[]。当我配置服务引用并将集合类型更改为“System.Collection.Generics.List”时,它在状态栏中显示它正在更新引用代码,但是 WPF 应用程序中的方法抛出错误,说明它可以't 隐式地从 List 转换为 Array。这似乎是在我将更新推送到服务器之后发生的,但唯一改变的是我的一个对象的初始化方式。到目前为止,我已经尝试过以下方法;
- 清理项目
- 清理解决方案
- 重建解决方案
- 手动删除了 obj/bin/Service Reference 文件夹
- 删除并重新发布了 wcf 服务
- 重新启动服务器
我完全不知所措,现在不知道该怎么办。非常感谢任何帮助!
更新
我创建了一个单独的控制台项目,一旦配置为返回列表,它就会正确连接到 WCF 服务。看起来是 WPF 项目的具体问题。
更新 2
当我尝试构建时,我注意到以下错误会短暂出现。它们会在一段时间后消失,但我不知道这是否与问题有关。它们都在 App.config 文件中。
“bindingConfiguration”属性无效 - 根据其数据类型“serviceBindingConfigurationType”,值“BasicHttpBinding_ICustomService”无效 - 枚举约束失败。
“合同”属性无效 - 根据其数据类型“clientContractType”,值“CustomServerSvc.ICustomServer”无效 - 枚举约束失败。
更新 3
有趣的是,这似乎只在构建后随机发生在客户端。
根据请求添加我的 web.config。
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="UnifyServer.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<connectionStrings>
<add name="DebugUnifyCS"
connectionString="connectionString"
providerName="System.Data.SqlClient" />
<add name="UnifyCS"
connectionString="connectionString"
providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<client />
<bindings>
<basicHttpBinding>
<binding name="myBasicBinding" maxBufferPoolSize="524288" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647" receiveTimeout="00:30:00" sendTimeout="00:30:00">
<readerQuotas maxDepth="128" maxStringContentLength="2147483647"
maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binding>
</basicHttpBinding>
</bindings>
<!--<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IUnifyServer" >
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>-->
<services>
<service name="UnifyServer.UnifyServer">
<endpoint address="UnifyServer" binding="basicHttpBinding" bindingConfiguration="myBasicBinding" contract="UnifyServer.IUnifyServer"></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://unifysrv2012:19081/"/>
</baseAddresses>
</host>
</service>
<service name="UnifyServer.ServiceEndpoint">
<endpoint address="ServiceEndpoint" binding="basicHttpBinding" bindingConfiguration="myBasicBinding" contract="UnifyServer.IServiceEndpoint"></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://unifysrv2012:19081/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
<applicationSettings>
<UnifyServer.Properties.Settings>
<setting name="UnifyServer_some_service" serializeAs="String">
<value>https://some.url.com/some_service.asmx</value>
</setting>
</UnifyServer.Properties.Settings>
</applicationSettings>
</configuration>
【问题讨论】:
-
那么当你添加一个新的服务引用时,你现有的代码库会被修改吗?
-
它看起来像是在资源管理器的服务引用文件夹下添加了相关文件,并且它确实更正了整个应用程序中所有丢失的引用。无论我将其配置为什么,它都会不断尝试将集合作为数组返回。
-
您是否使用相同的名称/命名空间?这些会导致冲突吗?
-
命名空间不同。客户端(WPF)应用程序不包含任何自定义对象,我只使用来自服务器的定义。
-
您说您正在开发服务和应用程序?那么,为什么不只是在客户端中重用该界面,而不是让 Visual Studio 尝试从 wsdl 中找出它呢?您的代码将更小更快,类型正确,甚至编译速度更快。
标签: c# .net wpf web-services wcf