在iis服务器中的Wcf restfull托管服务中获得400错误

时间:2018-04-13 09:49:48

标签: web-services wcf iis

使用json配置声明函数

namespace Wcf_Test2
 {

 [ServiceContract]
 public interface IMyService
 {
    [OperationContract]
    [WebInvoke(Method = "GET",
        ResponseFormat = WebMessageFormat.Json,
        BodyStyle = WebMessageBodyStyle.Bare,
        UriTemplate = "dowork")]
    string DoWork();
 }
 }

是返回字符串值的函数。

public class MyService : IMyService
{
    public string DoWork()
    {
        string str = "HI, Its's DOWork Running"; 
        return str;
    }
}

这是我使用的Web.config文件。

<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="false" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<services>
  <service behaviorConfiguration="Default" name="Wcf_Test2.MyService">
    <endpoint address="" binding="basicHttpBinding" 
 contract="Wcf_Test2.IMyService" />
    <endpoint address="mex" binding="mexHttpBinding" 
 contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost/Wcf_Test2/MyService.svc" />
      </baseAddresses>
    </host>
  </service>
 </services>
 <behaviors>
  <endpointBehaviors>
    <behavior name="webBehavior">
      <webHttp />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="Default">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
 </behaviors>
 </system.serviceModel>
 </configuration>

我将此托管的网络服务称为http://localhost/Wcf_Test2/MyService.svc/dowork 但是它回复了这个

The error is this which this picture is showing me.

0 个答案:

没有答案