WCF服务调用返回空文件/页面

时间:2016-03-21 13:09:13

标签: asp.net wcf iis wamp

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

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

设置: 如果需要,WAMP服务器将侦听80端口,然后重定向到IIS,以及特定端口。这是设置的一个示例。

Wamp config(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测试客户端我得到了这个:

&#13;
&#13;
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.
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:2)

您需要指定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

答案 1 :(得分:0)

不确定这个答案将在3年后对OP有所帮助。但这更适合@GothamLlianen。但是,如果要通过HTTPS连接访问WFC服务,则需要显式指定该绑定。

将其添加到Web.Config的<system.serviceModel>节点中

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