如何通过传递json
来发布调用SaveCorporateProfile函数[DataContract]
public class myclass
{
public string CompanyCode { get; set; }
public string Username { get; set; }
public string Password { get; set; }
}
[ServiceContract]
public interface ICustProfileService
{
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/SaveCorporateProfile?dt={dt}")]
string SaveCorporateProfile(myclass dt);
}
public string SaveCorporateProfile(myclass dt)
{
return "success";
}
答案 0 :(得分:0)
你可以试试这个;
首先,您应该像这样编辑 myclass ;
[DataContract]
public class myclass
{
[DataMember]
public string CompanyCode { get; set; }
[DataMember]
public string Username { get; set; }
[DataMember]
public string Password { get; set; }
}
那么你的界面就像这样;
[ServiceContract]
public interface ICustProfileService
{
[OperationContract]
string SaveCorporateProfile(myclass dt);
}
您实现.svc文件以使用此界面
public class CustProfileService: ICustProfileService
{
[WebInvoke(Method = "POST",UriTemplate = "/SaveCorporateProfile?dt={dt}"
BodyStyle = WebMessageBodyStyle.Bare,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
public string SaveCorporateProfile(myclass dt)
{
return "success";
}
}