Background
I have created ASMX web services in the past and have been able to access the service from the web browser and Ajax GET requests using the address convention:
MyService.asmx/MyMethod?Param=xxx
我刚刚开始使用WCF,并在我的ASP中创建了一个新的web服务.NET项目.它创建了一个带有.svc扩展,比如MyService.svc.
Current Situation
I am able to consume the service using the WcfTestClient
that comes with VS2008. I am also able to create my own WCF Client by either adding a service reference in another project or using the svcutil.exe
commandline to generate the proxy and config file.
The Problem
When I try to use the service from a browser using MyService.svc/MyMethod?MyParam=xxx
, I get a blank page without any errors.
What I have tried
I have already added a basicHttpBinding to the web.config and made it HttpGetEnabled in the behavior configuration. I also added the [WebGet(UriTemplate = "MyMethod?MyParam={MyParam}")]
attribute to my operation contract.
I have already followed the information in this other stack overflow question:
REST / SOAP EndPoints for a WCF Service
但是,在执行完这些步骤后,我要么得到一个空白页面,要么得到一个HTTP404错误.代码没有什么特别之处.我只是接受一个字符串作为参数,并返回"Hello xxx".这是一个基本的"Hello WCF World"概念验证类型.
UPDATE - Here's the relevant code
[ServiceContract]
public interface IMyService
{
[WebGet(UriTemplate = "MyMethod/MyParam={MyParam}")]
[OperationContract]
string MyMethod(string MyParam);
}
Web.Config - system.serviceModel Section
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="MyServiceBehavior" name="MyService">
<endpoint address=""
binding="wsHttpBinding" contract="IMyService" />
<endpoint address="MyService.svc"
binding="basicHttpBinding" contract="IMyService" />
<endpoint address="mex"
binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>