开发者

WCF: Consume a WCF service using jQuery and also a Windows Application

I've successfully consumed a WCF Service using jQuery by following this link: http://www.codeproject.com/KB/aspnet/WCF_JQUERY_ASMX.aspx

I just made a few modifications for my POCO entities to serialize properly. Everything works fine if consumed by jQuery or when viewed using the browser (changed verb to get).

Now I've created a windows application and added a service reference to this service. It successfully completes and I can see the classes/methods and all. However, when I try to run the application, I get the following error:

"Could not find default endpoint element that references contract [ContractName] in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element."

Based on this error, I guess I should create another endpoint to cater to non-http applications? I'm not really sure how it works though..

Here's my 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=&quot;Data Source=bdowrmg01;Initial Catalog=ORMU_Prototype;user=sa;password=Password1;MultipleActiveResultSets=True&quot;" 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>

Also, here's the contract:

[ServiceContract]
public interface IKCSA
{
    [OperationContract]
    [ApplyDataContractResolver]
    [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped,Method="GET",ResponseFormat=WebMessageFormat.Json)]
    JsonResponse<IEnumerable&l开发者_如何学编程t;KCSATopic>> GetTopics();
}


Service references only work with SOAP web-services (via a WSDL definition), not with Web HTTP (aka REST) services which is what you've got.

So you either need to use the HttpWebRequest class to consume your service, or add another binding to your service of type wsHttpBinding.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜