0
我是新來的WCF REST錯誤的請求,我創建了一個簡單的WCF應用程序,並嘗試使用它,但我不斷收到一個錯誤:WCF REST的服務回報(400)
The remote server returned an error: (400) Bad Request
我的方法:
[OperationContract]
[WebGet(UriTemplate="mymethod")]
string nameInput();
消耗通過使用此代碼:
string uri = "http://localhost:53551/HelloNameService.svc/mymethod";
req = (HttpWebRequest)WebRequest.Create(uri);
try
{
resp = req.GetResponse() as HttpWebResponse;
}
catch(Exception ex)
{
Console.WriteLine(ex);
}
Stream stream = resp.GetResponseStream();
StreamReader reader = new StreamReader(stream);
string value = reader.ReadToEnd();
label1.Text = value;
的web.config:
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehaviors">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="MyServiceBecouseError.MyNameService"
behaviorConfiguration="mexBehaviors">
<endpoint
address=""
binding="basicHttpBinding"
contract="MyServiceBecouseError.IMyNameService"/>
</service>
</services>
</system.serviceModel>
<system.webServer>
<directoryBrowse enabled="true"/>
</system.webServer>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>
您的localhost:53551是否可以訪問? –
@ThiyaguRajendran我怎麼知道? –
嘗試導航到http:// localhost:53551/HelloNameService.svc。端點應公開服務元數據。 – forik