I'm trying to self-host a WCF web service and provide a HTTP endpoint with ajax support. Pretty much everything I've found about WCF and AJAX are talking about IIS, which I don't want to use.
我正在尝试自托管WCF Web服务并为HTTP端点提供ajax支持。几乎我发现的关于WCF和AJAX的一切都在谈论IIS,我不想使用它。
I've build a simple Console App to host the service. My service only have a single method:
我已经构建了一个简单的控制台应用程序来托管服务。我的服务只有一个方法:
[ServiceContract]
interface IMyService
{
[OperationContract]
string TestConnection();
}
And here's the app.config code:
这是app.config代码:
<services>
<service name="Service.MyService" behaviorConfiguration="MyServiceBehavior" >
<endpoint address="" binding="webHttpBinding" behaviorConfiguration="WebBehavior" contract="Service.IMyService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
I can access the service metadata endpoint and see the WSDL, but I'm unable to use it from my ajax client. So my question are : 1. Is it possible to do this? 2. What is the needed configuration that I'm obviously missing?
我可以访问服务元数据端点并查看WSDL,但我无法从我的ajax客户端使用它。所以我的问题是:1。可以这样做吗? 2.我显然缺少什么配置?
NOTE I'm not using a .svc file
注意我没有使用.svc文件
Thanks!
谢谢!
1 个解决方案
#1
1
What is your client? With enableWebScript, you're getting ASP.NET AJAX support (eg, decorated members, types, and all the othe goo that implies). If you want "raw" JSON, use the webHttp behavior instead of enableWebScript, and tag your interface operations with WebInvokeAttribute or WebGetAttribute (setting the request/response types to JSON or XML as you wish). It also looks like you haven't attributed your interface with ServiceContractAttribute, which is required.
你的客户是什么?使用enableWebScript,您将获得ASP.NET AJAX支持(例如,装饰成员,类型以及所暗示的所有其他goo)。如果需要“原始”JSON,请使用webHttp行为而不是enableWebScript,并使用WebInvokeAttribute或WebGetAttribute标记接口操作(根据需要将请求/响应类型设置为JSON或XML)。看起来您还没有将您的接口归因于ServiceContractAttribute,这是必需的。
#1
1
What is your client? With enableWebScript, you're getting ASP.NET AJAX support (eg, decorated members, types, and all the othe goo that implies). If you want "raw" JSON, use the webHttp behavior instead of enableWebScript, and tag your interface operations with WebInvokeAttribute or WebGetAttribute (setting the request/response types to JSON or XML as you wish). It also looks like you haven't attributed your interface with ServiceContractAttribute, which is required.
你的客户是什么?使用enableWebScript,您将获得ASP.NET AJAX支持(例如,装饰成员,类型以及所暗示的所有其他goo)。如果需要“原始”JSON,请使用webHttp行为而不是enableWebScript,并使用WebInvokeAttribute或WebGetAttribute标记接口操作(根据需要将请求/响应类型设置为JSON或XML)。看起来您还没有将您的接口归因于ServiceContractAttribute,这是必需的。