我使用jQuery通过以下链接成功使用WCF服务:http://www.codeproject.com/KB/aspnet/WCF_JQUERY_ASMX.aspxWCF:使用jQuery消耗WCF服务,也可以在Windows应用程序
我只是做了我的POCO实体进行一些修改,以正确序列化。如果jQuery使用或使用浏览器查看(改变动词获取),一切工作正常。
现在我创建了一个Windows应用程序并添加了对此服务的服务引用。它成功完成,我可以看到类/方法和所有。但是,当我尝试运行该应用程序时,出现以下错误:
“在ServiceModel客户端配置部分找不到引用contract [ContractName]的默认端点元素,这可能是因为找不到配置文件您的应用程序,或者因为在客户端元素中找不到与此合同匹配的端点元素。“
基于这个错误,我想我应该创建另一个端点来迎合非http应用程序?我真的不知道它是如何工作,但..
这里是我的webconfig
<?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服务。你应该看看http://servicestack.net,在那里你可以花费更少的精力来构建一个完整的应用程序来配置一个WCF应用程序。检出完整的TODO应用程序http://www.servicestack.net/Backbone.Todos/和整个.cs源代码http://goo.gl/zA6hD – mythz 2011-05-13 10:09:01