我创建了一个REST WCF服务,该服务托管在IIS窗口服务器环境中。当我尝试从IIS访问服务(http://localhost:8081/Service1.svc/EmployeeDump)时,它将返回空白的xml响应。它不给出任何错误,仅返回空白xml。但是,可以从浏览器访问服务wsdl(元数据)文件。当我在Visual Studio上运行该服务时,该服务运行良好,并且端点方法以xml格式返回数据响应。但是当我在IIS服务器中托管相同的服务时,它返回空白响应,我不知道为什么。
我尝试从服务器管理器安装HTTP激活功能,并尝试更改Web配置参数(例如添加主机选项),但仍然存在相同的问题。
下面是我的网络配置:
<?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>
以下是我从IIS上托管的服务获得的空白xml响应:
<?xml version="1.0"?>
<ArrayOfEmployeeDump xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/MasterDumpService"/>
下面是我在浏览器上从Visual Studio运行服务时正确的xml响应(托管服务应实际返回):
<?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>
任何帮助将不胜感激。