2014-05-17 68 views
0

當我通過URL訪問Web服務時,它向我展示了所有可用的函數。我想限制在Web服務中公開顯示所有可用的功能。asp.net webservice函數公開顯示

換句話說,我希望這些功能可用於Web服務,但不會向用戶顯示。 需要什麼設置/代碼來完成此操作?

這裏是我的web.config代碼

Visual Studio中的Asp.Net配置選項。 的設置和註釋的完整列表可在 machine.config.comments通常位於 \的Windows \ Microsoft.Net \框架\ V2.X \配置 中找到 - >

</connectionStrings> 
<system.web> 
    <customErrors mode="Off" defaultRedirect="ErrorPage.htm"/> 
    <!-- 
     Set compilation debug="true" to insert debugging 
     symbols into the compiled page. Because this 
     affects performance, set this value to true only 
     during development. 
    --> 
    <compilation debug="true"> 
     <assemblies> 
      <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> 
      <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
      <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> 
      <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> 
      <add assembly="CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/> 
      <add assembly="CrystalDecisions.Shared, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/> 
      <add assembly="CrystalDecisions.ReportSource, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/> 
      <add assembly="CrystalDecisions.CrystalReports.Engine, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/><add assembly="CrystalDecisions.ReportAppServer.ClientDoc, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/><add assembly="CrystalDecisions.Enterprise.Framework, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/><add assembly="CrystalDecisions.Enterprise.InfoStore, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/></assemblies></compilation> 
    <!-- 
     The <authentication> section enables configuration 
     of the security authentication mode used by 
     ASP.NET to identify an incoming user. 
    --> 
<webServices> 
    <protocols> 
    <remove name="Documentation"/> 
    <!--<remove name="HttpSoap"/>--> 
    <!--<remove name="HttpSoap12"/>-->   
    </protocols> 
</webServices> 
    <sessionState timeout="01" mode="InProc"></sessionState> 
<authentication mode="Windows">  
</authentication> 

    <!--The <customErrors> section enables configuration 
     of what to do if/when an unhandled error occurs 
     during the execution of a request. Specifically, 
     it enables developers to configure html error pages 
     to be displayed in place of a error stack trace. 

    <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"> 
     <error statusCode="403" redirect="NoAccess.htm" /> 
     <error statusCode="404" redirect="FileNotFound.htm" /> 
    </customErrors>--> 
    <pages validateRequest="true" viewStateEncryptionMode="Always"> 
     <controls> 
      <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
      <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/></controls></pages> 
    <httpHandlers> 
     <remove verb="*" path="*.asmx"/> 
     <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
     <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
     <add verb="GET,HEAD" path="ScriptResource.axd" validate="false" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/><add verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/></httpHandlers> 
    <httpModules> 
     <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/></httpModules></system.web> 
<system.codedom> 
    <compilers> 
     <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4"> 
      <providerOption name="CompilerVersion" value="v3.5"/> 
      <providerOption name="WarnAsError" value="false"/></compiler> 
     <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4"> 
      <providerOption name="CompilerVersion" value="v3.5"/> 
      <providerOption name="OptionInfer" value="true"/> 
      <providerOption name="WarnAsError" value="false"/></compiler></compilers></system.codedom> 
<system.webServer> 
    <validation validateIntegratedModeConfiguration="false"/> 
    <modules> 
     <remove name="ScriptModule"/> 
     <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/></modules> 
    <handlers> 
     <remove name="WebServiceHandlerFactory-Integrated"/> 
     <remove name="ScriptHandlerFactory"/> 
     <remove name="ScriptHandlerFactoryAppServices"/> 
     <remove name="ScriptResource"/> 
     <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
     <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
     <add name="ScriptResource" verb="GET,HEAD" path="ScriptResource.axd" preCondition="integratedMode" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/><add name="CrystalImageHandler.aspx_GET" verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" preCondition="integratedMode"/></handlers></system.webServer> 
<runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
      <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/> 
      <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/></dependentAssembly> 
     <dependentAssembly> 
      <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/> 
      <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/></dependentAssembly></assemblyBinding></runtime></configuration> 
+0

是THI s ASMX,WCF SOAP,WCF Rest,ASP.NET Web API或其他系統? – Dai

+0

是的,它是一個ASMX系統。 – user2408256

回答

0

如果這是WCF,禁用服務元數據,在你的web.config文件做到這一點:

(從http://msdn.microsoft.com/en-us/library/ms751498(v=vs.110).aspx

要禁用WCF WSDL:

<behaviors> 
    <serviceBehaviors> 
     <behavior name="yourServiceBehavior"> 
      <!-- 
      The serviceMetadata behavior publishes metadata through 
      the IMetadataExchange contract. When this behavior is 
      present, you can expose this contract through an endpoint 
      as shown below. Setting httpGetEnabled to true publishes 
      the service's WSDL at the <baseaddress>?wsdl, for example, 
      http://localhost/servicemodelsamples/service.svc?wsdl 
      --> 
      <serviceMetadata httpGetEnabled="false"/> 
     </behavior> 
    </serviceBehaviors> 
</behaviors> 

要禁用WCF MEX,請刪除或註釋binding="mexHttpBinding"<endpoint>元,這將是這樣的:

<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 

(請注意,同時指定<serviceMetadata httpGetEnabled="false">也將禁用MEX,但MEX端點將仍然存在)

如果這是ASMX,把這個在您的配置:

<system.web>  
    <webServices> 
     <protocols> 
      <remove name="Documentation"/> 
     </protocols> 
    </webServices> 
</system.web> 

爲的ASP.NET Web API文檔頁面的處理方式不同,請參閱這篇文章的解釋:http://www.asp.net/web-api/overview/creating-web-apis/creating-api-help-pages

+0

我已經使用了ASMX配置,但是當我測試網絡服務時,它顯示錯誤描述**請求格式無法識別。** – user2408256

+0

@ user2408256請將您的整個web.config文件發佈到您的原始問題中。 – Dai