可能重复:
Bad Request 400 while accessing WCF Rest service (WebGet)
大家好,
让我解释一下我在使用WCF休息服务做什么。这是我的代码和配置:
IDNNService界面
[ServiceContract]
public interface IDNNService
{
[WebGet(ResponseFormat = WebMessageFormat.Xml, UriTemplate = "hello/{Name}")]
[OperationContract]
string SayHello(string Name);
}
服务类
public class DNNService : IDNNService
{
public string SayHello(string Name)
{
return string.Format("Hello {0}", Name);
}
}
配置文件
<system.serviceModel>
<services>
<service behaviorConfiguration="DNNServiceBehavior" name="DNNService">
<endpoint
address=""
binding="wsHttpBinding"
contract="IDNNService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
<endpoint
address="rest"
binding="webHttpBinding"
behaviorConfiguration="httpBehavior"
contract="IDNNService"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DNNServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="httpBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
我能够使用wsdl
生成返回正确信息的SVC文件但问题是当我尝试访问我的实际方法时
http://localhost/DC560X_rest/DesktopModules/DNNCentric-RestService/Entities/DNNService.svc/rest/hello/prabhakar
请帮帮我。 提前致谢
答案 0 :(得分:2)
您的网址看起来像松鼠一样坚固。
设置服务的URL
<system.serviceModel>
<services>
<service behaviorConfiguration="DNNServiceBehavior" name="DNNService">
<endpoint
address="http://*:12345/Derp"
binding="wsHttpBinding"
contract="IDNNService">
<identity>
(您可能必须确保端口12345未被防火墙阻止)
然后使用网址:http://localhost:12345/Derp
(当然,从安装它的同一台计算机上)来测试您的服务。