我试图通过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>
答案 0 :(得分: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>