从浏览器URL访问WCF方法

时间:2015-08-03 11:58:31

标签: c# vb.net wcf rest web-config

我有一个WCF服务,当我使用客户端(用c#,vb等编写)时,它可以正常工作。 有没有办法在addidtion中使用浏览器URL访问服务方法? 我尝试使用我在互联网上找到的所有样本来更改网络配置,但没有运气,我想我错过了一些东西。

<ServiceContract()>
Public Interface IJobsService
<OperationContract()> <WebGet()>
Function Test() As String

我在同一个类dataContract中有一个调用所有方法的类JobTool:

<DataContract()>
    Public Class JobsTool
      Shared Function Test() As String
          Return "Test function is OK."
      End Function

还有另一个类 - JobsService从BL中调用该方法:

Public Function Test() As String Implements IJobsService.Test
    Return BL.JobsTool.Test()
End Function

我的网页配置如下:

    <?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
    <httpRuntime maxRequestLength ="214748" executionTimeout="999" />
  </system.web>

    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior>
                    <!-- To avoid disclosing metadata information, set the value below to false before deployment -->
                    <serviceMetadata httpGetEnabled="true"/>
                    <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                    <serviceDebug includeExceptionDetailInFaults="false"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />    
    </system.serviceModel>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
        <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
        <directoryBrowse enabled="true"/>
    </system.webServer>

  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true">
        <listeners>
          <add name="traceListener"
              type="System.Diagnostics.XmlWriterTraceListener"
              initializeData= "c:\log\Traces.svclog" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
</configuration>

0 个答案:

没有答案