将电子邮件ID作为参数传递给WCF restful service

时间:2011-10-14 10:32:25

标签: wcf web-services

假设我有一个Web服务,它接受电子邮件ID和密码作为url中的参数。我必须通过电子邮件ID和密码验证用户。 using System;using System.Collections.Generic;using System.Linq;using System.Runtime.Serialization;using System.ServiceModel;using System.Text;using System.ServiceModel.Web;namespace WebApp.Services{[ServiceContract]public interface IService { [WebInvoke(Method = "GET", UriTemplate = "/authenticate/{emailId}/{password}", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)] [OperationContract] Boolean Authenticate(string emailId, string password); }}

我们称之为Web服务:

http://localhost:14176/Services/Service.svc/Authenticate/sushant.bhatnagar@greatdevelopers.com/123

因为电子邮件包含'。'它不是由Web浏览器编码的,因此不会调用Web服务功能。

除了查询字符串之外,还有任何解决方案可以在url中传递电子邮件ID。

1 个答案:

答案 0 :(得分:0)

如果您可以使用POST:

[ServiceContract]
public interface IMyService
{
     [OperationContract]
     bool Authenticate(EmailCredential request);
}

[DataContract]
public class EmailCredential 
{
     [DataMember]
     public string EmailId {get; set;}

     [DataMember]
     public string Password {get; set;}
}

并使用WebClient或WebHttpRequest使用该xml调用服务(我现在不知道json是如何为xml所示)

    <EmailCredential >
        <EmailId >sushant.bhatnagar@greatdevelopers.com</EmailId >
        <Password >123</Password >
    </EmailCredential >
相关问题