【问题标题】:The created svc Service is always SOAP创建的 svc 服务始终是 SOAP
【发布时间】:2013-06-16 04:29:00
【问题描述】:

我正在尝试创建 REST 网络服务:

打印.svc:

 <%@ ServiceHost Language="C#" Debug="true" Service="WcfService1.Print" CodeBehind="Print.svc.cs" %>

IPrint.cs:

[ServiceContract]
public interface IPrint
{
    [OperationContract]
    [WebInvoke(Method="GET",
        ResponseFormat= WebMessageFormat.Json,
        BodyStyle=WebMessageBodyStyle.Wrapped,
        UriTemplate="print/{id}")]
    string Printer(string id);
}

打印.cs

public string Printer(string id)
{
    return "hola" + id;
}

还有网络配置:

    <?xml version="1.0"?>
     <configuration>

      <appSettings>
        <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
      </appSettings>
      <system.web>
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5"/>
      </system.web>
      <system.serviceModel>
        <services>
         <service name="WcfService1.Print" behaviorConfiguration="ServiceBehaviour">
            <endpoint address="" binding="webHttpBinding" contract="WcfService1.IPrint" behaviorConfiguration="web"/>
         </service>
        </services>
     <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviour">         
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>          
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>                
      </endpointBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

所以,如果我输入:/Print.svc/Printer/chau 我应该有:“hola chau”

Insted,我得到: “未找到端点” 而且,如果我输入 /Print.svc:

You have created a service.

To test this service, you will need to create a client and use it to call the service. You can do this     using the svcutil.exe tool from the command line with the following syntax:

svcutil.exe http://localhost:8415/Print.svc?wsdl

You can also access the service description as a single file:
http://localhost:8415/Print.svc?singleWsdl

所以它是一个 SOAP WebService!我要它休息! 这是哪里的问题?

【问题讨论】:

    标签: .net wcf rest


    【解决方案1】:

    我犯了一个小错误:

       [WebInvoke(Method="GET",
            ResponseFormat= WebMessageFormat.Json,
            BodyStyle=WebMessageBodyStyle.Wrapped,
            UriTemplate="print/{id}")]
    

    UriTemplate 应该是“打印机/{id}”!!!!

    无论如何,我不明白为什么我可以对休息网络服务做一个 wsdl ???

    【讨论】:

    • REST 没有 WSDL 的概念——这是 SOAP 的一大优点。 REST 目前没有可比性-
    • 我知道,问题是我能够对其余服务进行 wsdl。
    猜你喜欢
    • 2015-05-28
    • 1970-01-01
    • 2023-03-26
    • 2011-01-03
    • 2016-11-01
    • 1970-01-01
    • 2013-05-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多