我有一個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>
我知道我錯過了一些東西,但我無法弄清楚 - 有沒有人有任何想法?
謝謝!