IIS上托管的WCF Web服务返回空的xml响应 [英] WCF webservice hosted on IIS returns empty xml response

查看:45
本文介绍了IIS上托管的WCF Web服务返回空的xml响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个休息的wcf服务,该服务托管在IIS窗口服务器环境中.当我尝试访问服务时(
随时让我知道是否有什么可以帮助您的.

I have created a rest wcf service that is hosted on IIS window server environment. When I try accessing the service(http://localhost:8081/Service1.svc/EmployeeDump) from IIS it returns blank xml response. It does not give any error, just a blank xml is returned. However, service wsdl(metadata) file is accessible from browser. The service works fine when I run it on Visual Studio and endpoint methods returns data response in xml. But when I host same service in IIS server, it returns blank response I don't know why.

I tried installing HTTP Activation feature from server manager and tried changing the web config parameters such as adding host option but still the same issue.

Below is my web config:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
  </configSections>
  <connectionStrings>
    <add name="MyDB"connectionString="server=xyz\abc;database=testDB;Integrated Security = SSPI;"/>
  </connectionStrings>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
  </appSettings>
  <system.web>
    <compilation targetFramework="4.6.1" debug="true"/>
    <httpRuntime targetFramework="4.6.1"/>
  </system.web>
  <system.serviceModel>
    <bindings>
      <webHttpBinding>
        <binding name="webHttpTransportSecurity">
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
    <services>
      <service name="MasterDumpService.Service1" behaviorConfiguration="myServiceBehavior">
        <endpoint address="" binding="webHttpBinding" behaviorConfiguration="webBehavior" contract="MasterDumpService.IService1"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8081/"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="myServiceBehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="MasterDumpService.ServiceAuthenticator, MasterDumpService"/>
          </serviceCredentials>
        </behavior>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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="true"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="webBehavior">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https"/>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 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>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb"/>
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
    </providers>
  </entityFramework>
</configuration>

Below is the blank xml response that I am getting from service hosted on IIS:

<?xml version="1.0"?>
<ArrayOfEmployeeDump xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/MasterDumpService"/>

And below is the correct xml response(which the hosted service should actually return) when I run the service from visual studio on browser:

<?xml version="1.0"?>

-<ArrayOfEmployeeDump xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/MasterDumpService">


-<EmployeeDump>

<BusinessUnit/>

<Department>E commerce</Department>

<DisplayName>Gayathri</DisplayName>

<Mail>gayathri@xyz.com</Mail>

</EmployeeDump>


-<EmployeeDump>

<BusinessUnit/>

<Department/>

<DisplayName>kiran</DisplayName>

<Mail>kiran@domain.com</Mail>

</EmployeeDump>


-<EmployeeDump>

<BusinessUnit/>

<Department/>

<DisplayName>xyz</DisplayName>

<Mail>xyz@domian.com</Mail>

</EmployeeDump>

Any help will be greatly appreciated.

解决方案

The key to the problem is the database connection. We could check the result returned by the EF entity by adding breakpoint when debugging.
When we deploy the service in the IIS, the connection string to the database had better use username/password instead of integrated security. Because the IIS app pool identity may differ from the current user running the VS.
Besides, when we deploy the service in the IIS, we should specify the base address in the IIS site binding module instead of the webconfig file.
Feel free to let me know if there is something I can help with.

这篇关于IIS上托管的WCF Web服务返回空的xml响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆