【问题标题】:WCF via HTTP GETWCF 通过 HTTP GET
【发布时间】:2011-07-07 09:05:14
【问题描述】:

我有一个 WCF 服务,我正试图通过浏览器访问它。它可以通过测试客户端正常工作,但是使用浏览器时不会调用我的断点[点。我的 web.config 有

<system.serviceModel>
    <client>
        <endpoint address="http://localhost:84/BillService.svc"
            binding="webHttpBindingConfig" bindingConfiguration="BasicHttpBinding_IBillService"
            behaviorConfiguration="json"
            contract="iBillService.IBillService" name="BasicHttpBinding_IBillService" />
    </client>
    <behaviors>
        <serviceBehaviors>
            <behavior name="">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
            <behavior name="Behavior">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
        </serviceBehaviors>
        <endpointBehaviors>
          <behavior name="json">
            <webHttp/>
          </behavior>
        </endpointBehaviors>
    </behaviors>

    <!-- turn off authentication in WCF, we get the client from the HttpContext -->
    <bindings>
        <basicHttpBinding>
            <binding name="CustomBasicAuth">
                <security mode="None">
                    <transport clientCredentialType="None" />
                </security>
            </binding>
            <binding name="BasicHttpBinding_IBillService" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="None">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
        </basicHttpBinding>
        <wsHttpBinding>
          <binding name="WsHttpBindingConfig">
            <security mode="TransportWithMessageCredential">
              <transport clientCredentialType="None" />
              <message clientCredentialType="UserName" />
            </security>
          </binding>
        </wsHttpBinding>
        <webHttpBinding>
          <binding name="webHttpBindingConfig">
            <security mode="None"/>
          </binding>
        </webHttpBinding>
    </bindings>

  <!-- to enable IIS authentication for WCF, we have to switch to compatibility mode -->
  <serviceHostingEnvironment aspNetCompatibilityEnabled="false"
    multipleSiteBindingsEnabled="true" />
  <services>
    <service name="WcfService"
             behaviorConfiguration="Behavior">
      <endpoint address=""
                binding="basicHttpBinding"
                bindingConfiguration="CustomBasicAuth"
                contract="IWcfService" />
    </service>
  </services>
</system.serviceModel>

我的接口定义是这样的:

<OperationContract()>
<WebInvoke(BodyStyle:=WebMessageBodyStyle.Bare, RequestFormat:=WebMessageFormat.Json, ResponseFormat:=WebMessageFormat.Json, Method:="GET")>
<WebGet(BodyStyle:=WebMessageBodyStyle.Bare, ResponseFormat:=ResponseFormat.Json)>
<ScriptMethod(UseHttpGet:=True, ResponseFormat:=ResponseFormat.Json)>
Function GetBills(ByVal userName As String, ByVal passwordHash As String) As List(Of Bill)

当我访问 URL 时

http://localhost:84/BillService.svc/GetBills?userName=demo&passwordHash=dummy

我得到一个空白页并且我的断点没有被触发

【问题讨论】:

  • 的定义在哪里?

标签: .net asp.net vb.net wcf web-services


【解决方案1】:

改变这个

<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="CustomBasicAuth"
contract="IWcfService" />

<endpoint address=""
binding="webHttpBinding"
bindingConfiguration="CustomBasicAuth"
contract="IWcfService" />

这可能有助于您使用 URL 访问您的服务

【讨论】:

  • 您还需要使用 行为,因此将其更改为 。另外,服务类的名称只是“WcfService”吗?您需要完全限定名称(与 BillService.svc 中使用的值相同)才能使配置生效。
【解决方案2】:

问题可能不在您的代码中,而在您的注释中。 WCF 可能会变得非常令人沮丧,因为您可以打开和关闭很多开关。首先添加一个

[ServiceBehavior(IncludeExceptionDetailInFaults = true)]

给你的服务实现。如果您仍然没有看到任何错误,您可以启用 WCF 跟踪: MSDN: Configuring WCF Tracing

对于 WCF 跟踪:

<configuration>
    <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>

【讨论】:

  • 似乎没有任何记录,无论是通过浏览器还是测试客户端。
  • 是的,在该页面上提到的其他配置中,我的配置标题中有这个:跨度>
  • 监听器元素也是?只想安全。我将编辑我的问题,以获得完整的配置部分。
  • 谢谢。我已将配置更改为此,但没有写入任何内容。当我使用测试客户端调用服务时,没有创建该文件。
  • 这是一个 MVC 应用程序吗?服务的路由可能由 MVC 控制器工厂而不是 WCF 处理。
猜你喜欢
  • 1970-01-01
  • 2023-03-18
  • 2013-06-22
  • 2017-11-30
  • 1970-01-01
  • 2017-05-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多