0
上周我创建了一个使用soap返回多行的asmx web服务。WCF - 返回多个记录
我现在正转向WCF,我也想做同样的事情。
在我的ASMX Web服务我做了以下..
public class sample
{
public string Id { get; set; }
public string Name { get; set; }
public string NameOfFile { get; set; }
//public int Distance { get; set; }
}
[WebMethod]
public sample[] Test(int count, float lat, float lng)
{
DataTable dt = new Gallery().DisplayNearestByLatLong(count, lat, lng);
var samples = new List<sample>();
foreach (DataRow item in dt.Rows)
{
var s = new sample();
s.Id = item[0].ToString();
s.Name = item[1].ToString();
s.NameOfFile = item[2].ToString();
//s.Distance = (int)item[3];
samples.Add(s);
}
return samples.ToArray();
}
此代码的工作很大,但现在我想这样做,但使用WCF。
我现在的WCF文件看起来像这样(我复制一个教程,但已经设置了数据契约(我认为这是需要的?))
GalleryWebService.cs
public class GalleryWebService : IGalleryWebService
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
return composite;
}
public CompositeType GetTestData()
{
return new CompositeType();
}
}
IGalleryWebService.cs
[ServiceContract]
public interface IGalleryWebService
{
[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
[OperationContract]
[WebGet(BodyStyle = WebMessageBodyStyle.Bare,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "test/random")]
CompositeType GetTestData();
}
[DataContract]
public class CompositeType
{
[DataMember]
string _id;
public string Id
{
get { return _id; }
set { _id = value; }
}
[DataMember]
string _name = "Hello";
public string Name
{
get { return _name; }
set { _name = value; }
}
[DataMember]
string _nameoffile = "Hello";
public string NameOfFile
{
get { return _nameoffile; }
set { _nameoffile = value; }
}
}
什么是最好的方式去做和如何做?非常感谢您的帮助!
在此先感谢。
O.k,我已经实现了,但是当我把它放在我的活的IIS Web服务器上时,它不起作用。这只是当我把DataTable放入时。你有什么想法吗? – tmutton 2010-12-11 14:34:53
我得到了错误.. IIS指定的身份验证方案'IntegratedWindowsAuthentication,Anonymous',但绑定仅支持完全确定一个身份验证方案的规范。有效的认证方案是摘要,协商,NTLM,基本或匿名。更改IIS设置,以便只使用单个身份验证方案。 – tmutton 2010-12-11 14:51:57
控制面板 - >管理工具 - > IIS - >选择一个网站或应用程序 - >双击Authentificcation图标 - >禁用集成Windows认证 – vorrtex 2010-12-11 16:10:15