我有一个ASP.NET应用程序,自ASMX日子以来一直存在。当我过去升级这个项目时,我能够通过扩展System.Web.Services.WebService类来利用WCF服务,然后利用WebInvoke属性来允许对我的各种方法进行RESTful调用。这里有一个例子:在Visual Studio 2013中WCF RESTful调用问题
[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)
{
该方法然后将没有问题转到http://10.23.41.189/seo.svc/login?User=USER&Pass=PASS
在旧的项目叫,我使用的是网站项目不是一个Web应用程序,现在我已经升级到Visual Studio 2013,我正在使用一个Web应用程序 - 并且该调用不再有效。我使用复制和粘贴将所有内容都移植到了一边,当我运行WSDL时,我看到了方法,但所有调用都返回了400错误请求错误。这里是我的web.config信息:
<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>
我知道我错过了一些东西,但我无法弄清楚 - 有没有人有任何想法?
谢谢!