剛開始調用WCF的時候一直報錯...
““System.ServiceModel.EndpointNotFoundException”類型的異常在 mscorlib.dll 中發生,但未在用戶代碼中進行處理”
“其他信息: 沒有終結點在偵聽可以接受消息的 http://xx.xx.xx.xx:端口//Service1.svc。這通常是由於不正確的地址或者 SOAP 操作導致的。如果存在此情況,請參見 InnerException 以了解詳細信息。”
點開詳細信息:“InnerException:{"遠程服務器返回錯誤: (404) 未找到。"}”
瀏覽器打開http://xx.xx.xx.xx:端口//Service1.svc/IService1/GetInfoByID 頁面顯示:“”未找到終結點。”
由此可見,是服務的問題了...
吾本以為簡單的一個問題,搜一下,答案便可出矣...哀哉悲哉...折騰過來折騰過去,沒毛線進展...
只好自己一步一個腳印來深入研究之,正好學習下...
了解的過程修改過來修改過去...
最終···得出一個結論...
不是IIS的問題就是web.config文件的配置問題...
最后一狠心...
將web.config全部刪了...
抄來了一個完好的例子
原文地址:http://www.cnblogs.com/wujy/p/3386993.html
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.web> <compilation debug="true" targetFramework="4.0" /> </system.web> <system.serviceModel> <behaviors> <endpointBehaviors> <behavior name="webHttp"> <webHttp helpEnabled="true"/> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="MapConfigBehavior"> <!-- 為避免泄漏元數據信息,請在部署前將以下值設置為 false 並刪除上面的元數據終結點 --> <serviceMetadata httpGetEnabled="true"/> <!-- 要接收故障異常詳細信息以進行調試,請將以下值設置為 true。在部署前設置為 false 以避免泄漏異常信息 --> <serviceDebug includeExceptionDetailInFaults="true"/> <dataContractSerializer maxItemsInObjectGraph="2147483647"/> </behavior> </serviceBehaviors> </behaviors> <bindings> <webHttpBinding> <binding name="webHttpBindConfig" receiveTimeout="00:30:00" sendTimeout="00:30:00" maxReceivedMessageSize="104857600"> <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647"/> <security mode="None"></security> </binding> </webHttpBinding> </bindings> <services> <service name="ServiceBll.UserBll" behaviorConfiguration="MapConfigBehavior"> <endpoint binding="webHttpBinding" contract="IServiceInterface.IUser" bindingConfiguration="webHttpBindConfig" behaviorConfiguration="webHttp"/> </service> </services> </system.serviceModel> </configuration>
...莫名其妙的好了...
現在是后台"添加服務引用"之后是可以調用服務了...
下一步還要解決.要前台ajax可以調用的方法...
支持 Ajax(只能算是一個折中的解決方案...No Pre)
web.config配置
<?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings> </appSettings> <system.webServer> <handlers> <remove name="WebDAV" /> </handlers> <modules runAllManagedModulesForAllRequests="true" > <remove name="WebDAVModule" /> </modules> <directoryBrowse enabled="true"/> <!--跨域..--> <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="*" /> <!--Content-Type,--> <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" /> <add name="Access-Control-Allow-Methods" value="GET,POST,PUT, DELETE, OPTIONS" /> </customHeaders> </httpProtocol> <security> <requestFiltering> <requestLimits maxQueryString="2147483640" maxUrl="2097151" maxAllowedContentLength="2097151"/> </requestFiltering> </security> </system.webServer> <system.web> <customErrors mode="Off"/> <compilation debug="true" targetFramework="4.0" /> <httpRuntime maxRequestLength="2147483647" maxUrlLength="2097151"/> </system.web> <system.serviceModel> <behaviors> <endpointBehaviors> <behavior name="webHttp"> <enableWebScript/> <!--2016年8月18日11:11:24--> <webHttp helpEnabled="true"/> </behavior> <!--<behavior name="webBehavior"> <webHttp helpEnabled="true"/> --> <!--<enableWebScript />--> <!-- </behavior>--> </endpointBehaviors> <serviceBehaviors> <behavior name="MapConfigBehavior"> <!-- 為避免泄漏元數據信息,請在部署前將以下值設置為 false 並刪除上面的元數據終結點 --> <serviceMetadata httpGetEnabled="true"/> <!-- 要接收故障異常詳細信息以進行調試,請將以下值設置為 true。在部署前設置為 false 以避免泄漏異常信息 --> <serviceDebug includeExceptionDetailInFaults="true"/> <dataContractSerializer maxItemsInObjectGraph="2147483647"/> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> <bindings> <webHttpBinding> <binding name="webHttpBindConfig" receiveTimeout="00:30:00" sendTimeout="00:30:00" maxReceivedMessageSize="2147483647" crossDomainScriptAccessEnabled="true"> <readerQuotas maxStringContentLength="2147483647" maxBytesPerRead="2147483647" maxArrayLength="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647"/> <security mode="None"> </security> </binding> </webHttpBinding> </bindings> <services> <service name="PreAlert_WcfService.Service1" behaviorConfiguration="MapConfigBehavior"> <endpoint address="" binding="webHttpBinding" contract="PreAlert_WcfService.IService1" bindingConfiguration="webHttpBindConfig" behaviorConfiguration="webHttp"/> <!--<endpoint address="" binding="webHttpBinding" contract="PreAlert_WcfService.IService1" bindingConfiguration="webHttpBindConfig" behaviorConfiguration="webHttp"/>--> </service> </services> </system.serviceModel> <connectionStrings> <add name="xxxxDBEntities" connectionString="metadata=res://*/EFModel.csdl|res://*/EFModel.ssdl|res://*/EFModel.msl;provider=System.Data.SqlClient;provider connection string="data source=x.x.x.x;initial catalog=xxxxDB;persist security info=True;user id=xxxx;password=xxxx;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /> <add name="SqlConnectionString" connectionString="Data Source=.;Initial Catalog=xxxx;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework" /> </connectionStrings> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
IService.cs
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Web; using System.Text; using System.IO; using System.Runtime.Serialization.Json; namespace xxxx_WcfService { // 注意: 使用“重構”菜單上的“重命名”命令,可以同時更改代碼和配置文件中的接口名“IService1”。 /// <summary> /// 契約接口 /// </summary> //[ServiceContract(Namespace = "")] [ServiceContract(Namespace = "PreAlertService")] public interface IService1 { #region T_Menu(菜單欄的權限控制) [OperationContract] [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)] string T_TabName_Add(string jsonParames); } }
Service.svc.cs
using Common; using DoMain; using fastJSON; using JS.Framework.Utility; using Service.ServiceImp; using System; using System.Collections.Generic; using System.Data; using System.Data.Entity; using System.Data.Entity.Infrastructure; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Net; using System.Reflection; using System.ServiceModel.Activation; using System.ServiceModel.Web; using System.Text; using System.Web; /* * 服務命名規范:表名_操作{例如:TabName_Action} */ namespace xxxx_WcfService { /// <summary> /// WCF服務 /// </summary> // 注意: 使用“重構”菜單上的“重命名”命令,可以同時更改代碼、svc 和配置文件中的類名“Service1”。 // 注意: 為了啟動 WCF 測試客戶端以測試此服務,請在解決方案資源管理器中選擇 Service1.svc 或 Service1.svc.cs,然后開始調試。 [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] //[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] [JavascriptCallbackBehavior(UrlParameterName = "jsoncallback")] //[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)] public class Service1 : IService1 { /// <summary> /// 增加xx信息 /// </summary> /// <param name="jsonParames">{ "xxxx":"xxxxID"}</param> /// <returns></returns> public string T_TabName_Add(string jsonParames) { #region Ajax... if (jsonParames == null && HttpContext.Current.Request.QueryString["jsonParames"] != null) jsonParames = HttpContext.Current.Request.QueryString["jsonParames"]; else if (jsonParames == null && HttpContext.Current.Request.QueryString["jsonParames"] == null) return JSON.Instance.ToJSON("{\"ret\":\"0\",\"msg\":\"參數為空.\"}"); #endregion }
Service.svc
<%@ ServiceHost Language="C#" Debug="true" Service="xxxx_WcfService.Service1" CodeBehind="Service.svc.cs" %>