【发布时间】:2011-05-13 09:58:56
【问题描述】:
我已通过以下链接使用 jQuery 成功使用 WCF 服务:http://www.codeproject.com/KB/aspnet/WCF_JQUERY_ASMX.aspx
我刚刚对我的 POCO 实体进行了一些修改以正确序列化。如果使用 jQuery 或使用浏览器查看(更改为获取的动词),一切正常。
现在我创建了一个 Windows 应用程序并添加了对该服务的服务引用。它成功完成,我可以看到类/方法和所有内容。但是,当我尝试运行应用程序时,出现以下错误:
“在 ServiceModel 客户端配置部分中找不到引用合约 [ContractName] 的默认端点元素。这可能是因为找不到您的应用程序的配置文件,或者因为在客户端中找不到与此合约匹配的端点元素元素。”
基于这个错误,我想我应该创建另一个端点来迎合非 http 应用程序?不过我不太确定它是如何工作的..
这是我的网络配置
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="EntityDataModelContainer" connectionString="metadata=res://*/EntityDataModel.csdl|res://*/EntityDataModel.ssdl|res://*/EntityDataModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=bdowrmg01;Initial Catalog=ORMU_Prototype;user=sa;password=Password1;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ORMDefaultServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="ORMDefaultServiceBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ORMDefaultServiceBehavior"
name="ORM.Business.KCSA">
<endpoint address="" binding="webHttpBinding"
contract="ORM.Business.IKCSA"
behaviorConfiguration="ORMDefaultServiceBehavior"/>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
另外,这是合同:
[ServiceContract]
public interface IKCSA
{
[OperationContract]
[ApplyDataContractResolver]
[WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped,Method="GET",ResponseFormat=WebMessageFormat.Json)]
JsonResponse<IEnumerable<KCSATopic>> GetTopics();
}
【问题讨论】:
-
仅托管一个 Web 服务就需要付出巨大的努力。您应该查看servicestack.net,您可以在其中构建整个应用程序,从而减少配置 WCF 应用程序所需的工作量。查看完整的 TODO 应用程序 servicestack.net/Backbone.Todos 和整个 .cs 源代码 goo.gl/zA6hD