wcf rest post服务端没法接收数据
wcf rest post服务端无法接收数据
做了一个wcf的reset服务,但是目前有一个问题,就是客户端可以GET调用,而POST调用就无法接收到数据,看看代码先
另外的一个svc文件中的方法
以上就是一个简单的服务,但是客户端在调用的时候服务端就是无法接收到account,监测account=null
下面是client
------解决方案--------------------
提示什么?
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/
做了一个wcf的reset服务,但是目前有一个问题,就是客户端可以GET调用,而POST调用就无法接收到数据,看看代码先
[ServiceContract(NameSpace="UserInfo")]
public interface IUser
{
[OperationContract]
[WebInvoke(UriTemplate="/AddUser",Method="POST",ResponseFormat=WebMessageFormat.Json,RequestFormat=WebMessageFormat.Json,BodyStyle=WebMessageBodyStyle.WrappedRequest)]
string Add(UserAccount account);
}
[DataContract]
public class UserAccount
{
[DataMember]
public int userId{get;set;}
......
}
另外的一个svc文件中的方法
public string Add(UserAccount account)
{
return account.name+"-"+account.age;
}
<system.ServiceModel>
<services>
<service name="Services1" behaviorConfiguration="webHttpBehaviors">
<endpoint contract="IServices1" binging="webHttpBinding" />
</service>
</services>
</system.ServiceModel>
以上就是一个简单的服务,但是客户端在调用的时候服务端就是无法接收到account,监测account=null
下面是client
DataContractJsonSerializer serializer=new DataContractJsonSerializer(typeof(UserAccount));
using(MemoryStream stream=new MemoryStream())
{
UserAccount account=new UserAccount{userId=1,......};
serializer.WriteObject(stream,account);
stream.Flush();
json=Encoding.UTF8.GetString(stream.toArray(),0,stream.Length);
client.Headers["Content-Type"]="application/json";
client.Encoding=Encoding.UTF8;
try
{
string res=client.UploadString(url,"POST",json);
}
catch
{
...
}
}
wcf
rest
post
服务端
数据无法接收
------解决方案--------------------
提示什么?
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/