【发布时间】:2012-10-17 21:00:26
【问题描述】:
我的简单示例 wcf 服务工作正常,但突然间它开始在“WCF 测试客户端”对话框中提示我输入端点地址。
我不记得更改任何会导致它从按 F5 时弹出浏览器 (IE 8) 到现在显示这个“WCF 测试客户端”的东西。
我不知道在它提供的编辑框中输入什么,所以我尝试了“http://localhost:4841/RestServiceImpl.svc”(http://localhost:4841/RestServiceImpl.svc/xml/123仍然可以在 Visual Studio 外部工作)
它接受(“服务添加成功”显示在对话框的任务栏中),但不执行其他任何操作;并单击“我的服务项目”树视图什么都不做(它没有孩子)。
更新
如果我尝试直接从 IE8 运行新操作,我会得到:
“/”应用程序中的服务器错误。
在合同“IRestServiceImpl”中,有多个使用方法“GET”和等同于“xml/{platypusId}”的 UriTemplate 的操作。每个操作都需要 UriTemplate 和 Method 的唯一组合来明确地发送消息。使用 WebGetAttribute 或 WebInvokeAttribute 更改操作的 UriTemplate 和 Method 值。
这是否意味着我只能有一个带字符串的 xml 返回操作?另一种/原始方法是 ...xml/{id}...
更新 2
这是代码,但仍然失败:
[ServiceContract]
public interface IRestServiceImpl
{
[OperationContract(Name="Foo")]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "xml/{id}")]
string XMLData(string id);
[OperationContract(Name="FooBar")]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "xml/{platypusId, anotherId}")]
string FirstTrial(string platypusId, string anotherId);
[OperationContract(Name="FooFooBar")]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "json/{id}")]
string JSONData(string id);
}
// 实现(.svc)文件
public class RestServiceImpl : IRestServiceImpl
{
public string XMLData(string id)
{
return "You requested product " + id;
}
public string FirstTrial(string platypusId, string anotherID)
{
return "I reckon so" + platypusId + anotherID;
}
public string JSONData(string id)
{
return "You requested product " + id;
}
}
【问题讨论】: