我在IIS上开发并部署了Rest Rested WCF服务但是当我从浏览器或My Asp.Net Mvc Consumer调用这些服务时,我得到 400错误请求错误。我也尝试通过 WCFStorm.REST 客户端调试服务,其中我收到以下错误:
System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
at RestSharp.Http.GetRawResponse(HttpWebRequest request)
at RestSharp.Http.GetResponse(HttpWebRequest request)
这是我的WCF配置:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpConfig"
allowCookies="true"
maxReceivedMessageSize="20000000"
maxBufferSize="20000000"
maxBufferPoolSize="20000000">
<readerQuotas maxDepth="32"
maxArrayLength="200000000"
maxStringContentLength="200000000" />
</binding>
<binding name="webHttpsConfig"
allowCookies="true"
maxReceivedMessageSize="20000000"
maxBufferSize="20000000"
maxBufferPoolSize="20000000">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
<readerQuotas maxDepth="32"
maxArrayLength="200000000"
maxStringContentLength="200000000" />
</binding>
<binding name="webHttpBindingXML" />
<binding name="webHttpBindingJSON" />
</webHttpBinding>
</bindings>
<services>
<service name="BusinessServices.UserService">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpsConfig" contract="BusinessServices.IUserService" behaviorConfiguration="web">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="XML" binding="webHttpBinding" bindingConfiguration="webHttpBindingXML" contract="BusinessServices.IUserService" behaviorConfiguration="RestXMLEndpointBehavior" />
<endpoint address="JSON" binding="webHttpBinding" bindingConfiguration="webHttpBindingJSON" contract="BusinessServices.IUserService" behaviorConfiguration="RestJSONEndpointBehavior" />
<host>
<baseAddresses>
<add baseAddress="https://localhost:7743/UserService.svc" />
</baseAddresses>
</host>
</service>
<service name="BusinessServices.RoleService">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpConfig" contract="BusinessServices.IRoleService" behaviorConfiguration="web">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="XML" binding="webHttpBinding" bindingConfiguration="webHttpBindingXML" contract="BusinessServices.IRoleService" behaviorConfiguration="RestXMLEndpointBehavior" />
<endpoint address="JSON" binding="webHttpBinding" bindingConfiguration="webHttpBindingJSON" contract="BusinessServices.IRoleService" behaviorConfiguration="RestJSONEndpointBehavior" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:7742/RoleService.svc" />
</baseAddresses>
</host>
</service>
<service name="BusinessServices.CriminalService">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpConfig" contract="BusinessServices.ICriminalService" behaviorConfiguration="web">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="XML" binding="webHttpBinding" bindingConfiguration="webHttpBindingXML" contract="BusinessServices.ICriminalService" behaviorConfiguration="RestXMLEndpointBehavior" />
<endpoint address="JSON" binding="webHttpBinding" bindingConfiguration="webHttpBindingJSON" contract="BusinessServices.ICriminalService" behaviorConfiguration="RestJSONEndpointBehavior" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:7742/CriminalService.svc" />
</baseAddresses>
</host>
</service>
<service name="BusinessServices.NationalityService">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpConfig" contract="BusinessServices.INationalityService" behaviorConfiguration="web">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="XML" binding="webHttpBinding" bindingConfiguration="webHttpBindingXML" contract="BusinessServices.INationalityService" behaviorConfiguration="RestXMLEndpointBehavior" />
<endpoint address="JSON" binding="webHttpBinding" bindingConfiguration="webHttpBindingJSON" contract="BusinessServices.INationalityService" behaviorConfiguration="RestJSONEndpointBehavior" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:7742/NationalityService.svc" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
<behavior name="RestJSONEndpointBehavior">
<webHttp helpEnabled="true" defaultOutgoingResponseFormat="Json" />
</behavior>
<behavior name="RestXMLEndpointBehavior">
<webHttp helpEnabled="true" defaultOutgoingResponseFormat="Xml" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<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>
</behaviors>
<protocolMapping>
<add binding="webHttpBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
ASP.NET MVC客户端端点:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="WebHttpBinding_ICriminalService" />
<binding name="WebHttpBinding_IRoleService" />
<binding name="WebHttpsBinding_IUserService" />
<binding name="WebHttpBinding_INationalityService" />
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="webEndpoint">
<webHttp defaultBodyStyle="Wrapped" helpEnabled="true"/>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="http://localhost:7742/CriminalService.svc" behaviorConfiguration="webEndpoint" binding="webHttpBinding" bindingConfiguration="WebHttpBinding_ICriminalService" contract="CriminalServiceReference.ICriminalService" name="WebHttpBinding_ICriminalService" />
<endpoint address="http://localhost:7742/RoleService.svc" behaviorConfiguration="webEndpoint" binding="webHttpBinding" bindingConfiguration="WebHttpBinding_IRoleService" contract="RoleServiceReference.IRoleService" name="WebHttpBinding_IRoleService" />
<endpoint address="https://localhost:7743/UserService.svc" behaviorConfiguration="webEndpoint" binding="webHttpBinding" bindingConfiguration="WebHttpsBinding_IUserService" contract="UserServiceReference.IUserService" name="WebHttpsBinding_IUserService" />
<endpoint address="http://localhost:7742/NationalityService.svc" behaviorConfiguration="webEndpoint" binding="webHttpBinding" bindingConfiguration="WebHttpBinding_INationalityService" contract="NationalityServiceReference.INationalityService" name="WebHttpBinding_INationalityService" />
</client>
</system.serviceModel>
样本服务合同:
[ServiceContract]
[ValidationBehavior]
public interface INationalityService : IDisposable
{
[OperationContract]
[FaultContract(typeof(ValidationFault))]
[WebInvoke(UriTemplate = "", Method = "POST")]
void Create(NationalityDTO Nationality);
[OperationContract]
[FaultContract(typeof(ValidationFault))]
[WebGet(UriTemplate = "")]
IEnumerable<NationalityDTO> GetNationalities();
}
P.S。:我已尝试过几乎所有可能并且可在互联网上发布的内容/ SO ,但无济于事。提前谢谢。
更新: - 我尝试将服务项目调试为Visual Studio启动项目,但它可以单独运行。只有在访问IIS上发布和托管的问题时才会出现此问题。