0

我正在尝试第一次通过 JSON 使用简单的 WCF RESTful。我的界面在下面,但调用 MemberLogon() 方法的 URL 是什么?

我以为会是这样:

http://localhost:49701/Exchange.svc/?membershipNumber=6519548&blah=abc

但我得到了 404。我感觉这与我的 Web.Config 中的服务配置有关。帮助!

我的界面和类是:

[ServiceContract]
public interface IExchange
{
    [System.ServiceModel.OperationContract(Name = "MemberLogon")]
    [WebInvoke(UriTemplate = "/?membershipNumber={membershipNumber}&blah={blah}", Method = "GET", ResponseFormat = WebMessageFormat.Json)]
    Member MemberLogon(string membershipNumber, string blah);
}

[System.Runtime.Serialization.DataContract]
public class Member
{
    [System.Runtime.Serialization.DataMember]
    public string Username { get; set; }
}

配置是:

  <system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="MyNamespace.MyClass.ExchangeBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
  <service behaviorConfiguration="MyNamespace.MyClass.ExchangeBehavior" name="MyNamespace.MyClass.Exchange">
    <endpoint address="" binding="webHttpBinding" contract="MyNamespace.MyClass.IExchange" />
  </service>
</services>

4

1 回答 1

1

代码和界面看起来不错。你可以试试这个配置吗?

<system.serviceModel>
            <behaviors>
              <endpointBehaviors>
                <behavior name="MyNamespace.MyClass.ExchangeBehavior">
                  <webHttp/>
                </behavior>
              </endpointBehaviors>
            </behaviors>
            <services>
              <service name="MyNamespace.MyClass.Exchange">
                <endpoint address="" binding="webHttpBinding" behaviorConfiguration="MyNamespace.MyClass.ExchangeBehavior" contract="MyNamespace.MyClass.IExchange" />
              </service>
            </services>
       </system.serviceModel>
于 2012-04-08T16:43:15.200 回答