【发布时间】:2018-10-27 20:37:00
【问题描述】:
我的 App.config 文件是
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service name="WcfJsonRestService.Service1">
<endpoint address="http://localhost:8733/service1"
binding="webHttpBinding"
contract="WcfJsonRestService.IService1"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior>
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
我的 service1.cs 代码如下
using System;
using System.ServiceModel.Web;
namespace WcfJsonRestService
{
public class Service1 : IService1
{
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "data/{id}")]
public Person GetData(string id)
{
// lookup person with the requested id
return new Person()
{
Id = Convert.ToInt32(id),
Name = "Leo Messi"
};
}
}
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
}
}
最初这是给问题的
WCF 服务主机配置 - 请尝试将 HTTP 端口更改为 8733
所以我按照在 CMD 中执行以下代码
netsh http add urlacl url=http://+:8733/ user=WORK\Clara
我该如何解决这个问题?
我也尝试过更新 App.Config,如下面链接所述,但后来又遇到了一些错误
【问题讨论】:
-
您提到的链接包含您的解决方案,您在更新 webconfig 时遇到了什么错误?如果在 IIS 上,请确保您正在编辑 Web.config(不是 App.config)。
-
@EzLo wenconfig 不存在,我有 app.config,我正在本地运行,即 Visual Studio
标签: wcf wcf-data-services wcf-ria-services wcf-binding wcf-security