2012-03-15 84 views
2

當我嘗試從瀏覽器中點擊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

回答

2

您已經使用在端點定義的的wsHttpBinding。只需將其更改爲webHttpBinding,即可使其工作。

0

首先,使用WebGet進行GET請求。其次,在沒有服務合同界面的情況下獲得服務,然後在其工作時將合同移動到界面中。

這個工作對我來說:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] 
[ServiceContract] 
public class HelloService 
{ 

    [WebGet(UriTemplate = "helloworld")] 
    [OperationContract] 
    public string HelloWorld() 
    { 
     return "Hello World!"; 
    } 

} 
+0

不適合我 – 1Mayur 2012-03-15 10:50:30

+0

我想知道我上面的代碼有什麼問題.. dnt想要替代 – 1Mayur 2012-03-15 11:37:06

+0

我想說你的web服務調用是正確的,必須是配置 – reach4thelasers 2012-03-15 11:44:35