在GET/POST方法中给出400错误请求的WCF方法
问题描述:
当我尝试从浏览器中点击URL时,我新创建了一个WCF并且m面临400错误请求错误。在GET/POST方法中给出400错误请求的WCF方法
我的服务合同看起来像
[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "GetUsers")]
string GetUsers();
我已在webconfig的条目
<serviceMetadata httpGetEnabled="true"/>
网址我打了浏览器
http://localhost:51561/AceWebService.svc/GetUsers
这里是部分webconfig:
<system.serviceModel>
<services>
<service name="AceWebService.AceWebService" behaviorConfiguration="AceWebService.AceWebServiceBehavior">
<!-- Service Endpoints -->
<endpoint address="" binding="wsHttpBinding" contract="AceWebService.IAceWebService">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="AceWebService.AceWebServiceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
已经提到所有问题在这里stackoverflow ..没有得到任何帮助..请建议的变化。
thnx
答
您已经使用在端点定义的的wsHttpBinding。只需将其更改为webHttpBinding,即可使其工作。
答
首先,使用WebGet进行GET请求。其次,在没有服务合同界面的情况下获得服务,然后在其工作时将合同移动到界面中。
这个工作对我来说:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
[ServiceContract]
public class HelloService
{
[WebGet(UriTemplate = "helloworld")]
[OperationContract]
public string HelloWorld()
{
return "Hello World!";
}
}
不适合我 – 1Mayur 2012-03-15 10:50:30
我想知道我上面的代码有什么问题.. dnt想要替代 – 1Mayur 2012-03-15 11:37:06
我想说你的web服务调用是正确的,必须是配置 – reach4thelasers 2012-03-15 11:44:35