简体   繁体   中英

WCF RESTful Calling Issue in Visual Studio 2013

I have an ASP.NET application which has been around since the ASMX days. When I upgraded this project in the past, I was able to utilize a WCF service by extending the System.Web.Services.WebService class and then utilize WebInvoke attributes to allow for RESTful calls to my various methods. Here is an example:

[ServiceContract(Namespace = "http://10.23.41.189/", Name = "SEO")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class SEO : System.Web.Services.WebService
{
    [WebMethod(Description = "Use this Web Method to log into The SEO Panel")]
    [OperationContract]
    [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
        UriTemplate = "Login?User={User}&Pass={Pass}")]
    public string Login(string User, string Pass)
    {

That method would then be called without issue by going to http://10.23.41.189/seo.svc/login?User=USER&Pass=PASS

In the old project, I was using a web site project not a web application and now that I have upgraded to Visual Studio 2013, I am using a web application - and that call no longer works. I literally ported everything over using copy and paste, when I run the WSDL, I see the methods, but all calls come back with a 400 Bad Request error. Here is my web.config information:

<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
  multipleSiteBindingsEnabled="true" />
<services>
  <service name="SEO">
    <endpoint address="http://10.23.41.189/SEO.svc" behaviorConfiguration="json" binding="webHttpBinding" name="MainHttpPoint" contract="SEOPlatform.Intranet.SEO"/>
    <endpoint address="mex" binding="mexHttpBinding" name="MexEP" contract="IMetadataExchange"/>
    <host>
      <baseAddresses>
        <add baseAddress="http://10.23.41.189/SEO.svc"/>
      </baseAddresses>
    </host>
  </service>
</services>
<bindings>
  <webHttpBinding>
    <binding openTimeout="00:10:00" sendTimeout="00:10:00" useDefaultWebProxy="false">
      <readerQuotas maxDepth="32" maxStringContentLength="2048000" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
    </binding>
  </webHttpBinding>
</bindings>
<behaviors>
  <endpointBehaviors>
    <behavior name="json">
      <webHttp helpEnabled="false" automaticFormatSelectionEnabled="false" defaultBodyStyle="Bare"/>
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" httpGetBinding="webHttpBinding" httpGetBindingConfiguration=""/>
      <serviceDebug httpHelpPageEnabled="false" httpsHelpPageEnabled="false" includeExceptionDetailInFaults="true"/>
      <useRequestHeadersForMetadataAddress>
        <defaultPorts>
          <add scheme="http" port="80"/>
        </defaultPorts>
      </useRequestHeadersForMetadataAddress>
    </behavior>
  </serviceBehaviors>
</behaviors>
</system.serviceModel> 

I know that I am missing something but I cannot figure it out - does anybody have any ideas?

Thank you!

I swear I should have just waited - I often write questions here and then the related questions always has the answer I need. This time that did not happen but, as I entered the web.config data, I discovered the issue. Rather than delete this question, I figured I would post an answer to hopefully help others.

The problem was with the service name:

<services>
  <service name="SEO">

With a web site project, the rules are lax but a web application requires the proper notation. All I did was change this to:

<services>
  <service name="SEOPlatform.Intranet.SEO">

And that fixed the issue. I also changed the multipleSiteBindingsEnabled to false but if you need that to be true there are great answers already posted elsewhere on this site.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM