1

I have this code inside my WCF Interface:

[OperationContract]
        [WebGet(UriTemplate = "/GetData/", ResponseFormat = WebMessageFormat.Json)]
        string GetData();

And this inside my Service page:

public string GetData()
{
     return "Please help";
}

I want to get the value of GetData function when I call it in url:

http://localhost: 12345/Services/MyWCF.svc/GetData/

After entering this url, I should be able to download the result inside the notepad due to JSON format. I'm not sure what went wrong with my WCF.

Please help!

Please let me know if I haven't make my question clear.

Thanks in advance.

4

1 回答 1

0

The must use a specific binding & a web http behavior for this. Suppose my service is under WebApplication1.Services.MyWCF, the config should be :

<system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior name="MyServiceBehavior">
                <serviceMetadata httpGetEnabled="true"    />
                <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
        </serviceBehaviors>
        <endpointBehaviors>
            <behavior name="WebBehavior">
                <webHttp />
            </behavior>
        </endpointBehaviors>
    </behaviors>
    <services>
        <service behaviorConfiguration="MyServiceBehavior" name="WebApplication1.Services.MyWCF">
            <endpoint address="" binding="webHttpBinding" behaviorConfiguration="WebBehavior" contract="WebApplication1.Services.IMyWCF"/>

        </service>
    </services>
</system.serviceModel>

If you are under .Net 4, protocol mapping will also help you a lot. Look here.

于 2013-04-16T14:42:45.830 回答