【问题标题】:WCF service call returns empty file / pageWCF 服务调用返回空文件/页面
【发布时间】:2016-03-21 13:09:13
【问题描述】:

问题: 当我调用已部署的 WCF 服务时,浏览器会下载一个空的 svc 文件,并且不会向我显示包含服务 xml 文件的页面。

上下文: 我必须将托管 WCF 服务的 webapp 移动到新服务器。该服务在运行 IIS 的旧服务器上运行良好。 新服务器有 2 个网络服务器正在运行。 IIS 8.5 和 WAMP 2.5,因为服务器托管了一个 Php 应用和 Jira。

设置: WAMP 服务器侦听 80 端口,然后根据需要重定向到 IIS 和特定端口。这是一个设置示例。

Wamp 配置(https-vhosts.confg):

<VirtualHost *:80>    
ServerName site.de
ServerAlias www.site.de 
<Proxy *>
    Require all granted
</Proxy>

ProxyRequests           Off
ProxyPreserveHost       On
ProxyPass               /       http://localhost:9050/
ProxyPassReverse        /       http://localhost:9050/

服务网址: https://www.site.de/folder/service.svc

服务配置:

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="someBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="52428899">
      <readerQuotas maxDepth="64" maxStringContentLength="81920" maxArrayLength="163840" maxBytesPerRead="40960" maxNameTableCharCount="163840" />
      <security mode="Transport">
        <transport clientCredentialType="None" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<behaviors>

  <serviceBehaviors>
    <behavior name="LargeServiceBehavior">
      <serviceMetadata httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <dataContractSerializer maxItemsInObjectGraph="2147483647" />
      <useRequestHeadersForMetadataAddress />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />

<services>
  <service name="ExampleServices.ExampleService" behaviorConfiguration="LargeServiceBehavior">
    <endpoint address="http://www.site.de/folder/service.svc" 
    binding="basicHttpBinding"
    bindingConfiguration="someBinding" 
    contract="ExampleServiceModels.IExampleService" />
  </service>
</services>

我以前从未使用过 wamp。而且我对 WCF 设置也没有太多经验。任何想法或提示将不胜感激。

编辑 使用 wcf 测试客户端我得到了这个:

Error: Cannot obtain Metadata from http://www.site.de/folder/ExampleService.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://www.site.de/folder/ExampleService.svc Metadata contains a reference that cannot be resolved: 'http://www.site.de/folder/ExampleService.svc'. The requested service, 'http://www.site.de/folder/ExampleService.svc' could not be activated. See the server's diagnostic trace logs for more information.HTTP GET Error URI: http://www.site.de/folder/ExampleService.svc The document at the url http://www.site.de/folder/ExampleService.svc was not recognized as a known document type.The error message from each known type may help you fix the problem:- Report from 'XML Schema' is 'Root element is missing.'.- Report from 'DISCO Document' is 'Root element is missing.'.- Report from 'WSDL Document' is 'There is an error in XML document (0, 0).'. - Root element is missing.

【问题讨论】:

  • 我认为这与 IIS 配置有关,请将旧服务器设置与新设置进行比较。

标签: asp.net wcf iis wamp


【解决方案1】:

您需要指定一个 MEX(元数据交换)绑定来公开您的 WSDL。示例(查看地址“mex”):

<service name="ExampleServices.ExampleService" behaviorConfiguration="LargeServiceBehavior">
    <endpoint address="http://www.site.de/folder/service.svc" binding="basicHttpBinding"
         bindingConfiguration="someBinding" 
    contract="ExampleServiceModels.IExampleService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>

在浏览器中获取 wsdl 类型: https://www.site.de/folder/service.svc?wsdl

【讨论】:

  • 感谢您的回答。我添加了,没有做任何事情。
【解决方案2】:

不确定这个答案是否会在将近 3 年后对 OP 有所帮助。但它更适用于@GothamLlianen。但是,如果您想通过 HTTPS 连接访问 WFC 服务,则需要明确指定该绑定。

将此添加到 Web.Config 的 &lt;system.serviceModel&gt; 节点中

<bindings>
  <webHttpBinding>
    <binding name="HttpsBinding">
      <security mode="Transport">
        <transport clientCredentialType="None"/>
      </security>
    </binding>
  </webHttpBinding>
</bindings>

然后将name,在本例中为“HttpsBinding”添加到端点

<endpoint bindingConfiguration="HttpsBinding"

以下完整节点供参考

  <system.serviceModel>
    <services>
      <service behaviorConfiguration="ServiceBehaviour" name="MyProject.Api">
        <endpoint bindingConfiguration="HttpsBinding" address="" behaviorConfiguration="web" binding="webHttpBinding" contract="MyProject.IApi" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviour">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
          <serviceAuthorization principalPermissionMode="UseAspNetRoles" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp defaultOutgoingResponseFormat="Json" defaultBodyStyle="Bare" />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <bindings>
      <webHttpBinding>
        <binding name="HttpsBinding">
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
  </system.serviceModel>

【讨论】:

  • 很抱歉,我无法及时对此进行测试。我们决定使用异步控制器来解决这个问题。由于它是网站中的旧 Asmx 服务,我们想用更新的 wcf 替换,Async 控制器似乎已经完成了这项工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多