【问题标题】:Self hosting WCF service: unable to use wcfTestClient - unable to get metadata自托管 WCF 服务:无法使用 wcfTestClient - 无法获取元数据
【发布时间】:2016-04-03 15:58:44
【问题描述】:

该服务确实可以正常工作,但由于某种原因,我无法使用 wcftestclient.exe 从本地 PC 到服务器 - 我想使用 wcftestclient.exe 调用方法。

它都是公司内部的、自托管的(在 Windows 服务中运行,没有 iis)。 framework 4. Basichttpbinding,不需要任何安全的东西。

这是我的 servicemodelconfig ...

<system.serviceModel>
    <services>
      <service name="myService">

        <endpoint
          address="http://servername:8001/myService" 
          binding="basicHttpBinding"
          contract="IMyService" />

      </service>
    </services>


    <behaviors>
      <serviceBehaviors>
        <behavior name ="MyDefaultBehaviour">
          <serviceMetadata httpGetEnabled="true" httpGetUrl="http://servername:8001/myService/mex" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceThrottling maxConcurrentCalls="1" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

我明白了……

错误:无法从中获取元数据 如果这是您有权访问的 Windows (R) Communication Foundation 服务,请检查您是否已在指定地址启用元数据发布。有关启用元数据发布的帮助,请参阅位于 http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange 错误 URI 的 MSDN 文档:

元数据包含无法解析的引用:'。内容类型应用程序/soap+xml;服务不支持 charset=utf-8

客户端和服务绑定可能不匹配。远程服务器返回错误:(415)无法处理消息,因为内容类型'application/soap+xml; charset=utf-8' 不是预期的类型 'text/xml; charset=utf-8'..HTTP GET 错误 URI:

下载“http://”时出错

请求失败,HTTP 状态 400:错误请求。

我已经把上面的服务器名删掉了,有很多空白,但希望信息足够清楚。

我确实尝试过添加额外的端点...

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

但是这样一来,windows 服务就无法启动了。

谢谢

----- 稍后添加 --- 也尝试过,但再次,服务没有启动

<system.serviceModel>
    <services>
      <service name="myService" behaviorConfiguration="MyDefaultBehaviour">
        <host>
          <baseAddresses>
            <add baseAddress="http://myServer:8001/myService" />
          </baseAddresses>
        </host>

        <endpoint
          address=""
          binding="basicHttpBinding"
          contract="Contracts.ImyService" />

        <endpoint
          address="mex"
          binding="mexHttpBinding"
          contract="IMetaDataExchange" />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name ="MyDefaultBehaviour">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceThrottling maxConcurrentCalls="1" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

【问题讨论】:

    标签: c# wcf utf-8


    【解决方案1】:

    如果添加 mexendpoint,则需要添加 baseAddress: 如下:

    <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange">
              <identity>
                <dns value="localhost"/>
              </identity>
            </endpoint>
            <host>
              <baseAddresses>
                <add baseAddress="net.tcp://localhost:9999/WcfTcp/Service1"/>
              </baseAddresses>
            </host>
    

    【讨论】:

    • 谢谢@Grady - 我确实尝试过基地址方式,但不是在端点标签内,而是在服务标签内,但windows服务无法启动。另外,我正在使用 http。
    【解决方案2】:

    毕竟,我的第二个配置确实有效,即使用基本地址、标准端点的空字符串和“mex”端点。 IMetadataExchange 的大写字母 D 拼写不正确。已排序。非常感谢@Grady

    【讨论】:

      猜你喜欢
      • 2011-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多