我正在尝试使用Azure服务的第一个web应用程序服务。我在VS中创建了它,它在本地工作。它所做的只是返回一个字符串,表示"hello user"是JSON。
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1
{
// To use HTTP GET, add [WebGet] attribute. (Default ResponseFormat is WebMessageFormat.Json)
// To create an operation that returns XML,
// add [WebGet(ResponseFormat=WebMessageFormat.Xml)],
// and include the following line in the operation body:
// WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
[OperationContract]
[WebGet(UriTemplate = "/DoWork")]
public string DoWork()
{
// Add your operation implementation here
return "hello user";
}
// Add more operations here and mark them with [OperationContract]
}
}
问题是当我发布它时,说成功。我能看到它在传送门上运行。当我进入发布的网站时,我得到的是标准的这个WEB应用程序已经成功创建,但是……当我将/DoWork添加到URL时,我得到HTTP错误404。
我知道我一定错过了一些简单的东西…什么好主意吗?您遗漏了服务的名称。在你的例子中是这样的:
http://engineappservicev001.azurewebsites.net/something.svc/dowork更多信息在这里:
http://www.codeproject.com/Articles/571813/A-Beginners-Tutorial-on-Creating-WCF-REST-Services