WCF - 同时接收HTTP响应为http发生错误:// XXXXX /服务/ [英] WCF - An error occurred while receiving the HTTP response to http://xxxxx/Service/

查看:854
本文介绍了WCF - 同时接收HTTP响应为http发生错误:// XXXXX /服务/的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您downvote之前,我知道有这样一出有重复的问题,但我尝试和寻找在他们的解决方案没有成功。 。可能是我错过了什么,但我还是比较新的WCF所以它的一些越过我的头有点



我正在在我的WCF服务该调用:

 公共用户GetStudentRecord(用户名字符串)
{

{
返回新DashboardFacade()GetStudentRecord(用户名)。
}
赶上(异常前)
{
ServiceFault故障=新ServiceFault();
fault.Operation =GetStudentRecord;
fault.Reason =谁知道呢......;
fault.Message = ex.Message;
抛出新的FaultException< ServiceFault>(故障,fault.Message,新的faultcode(fault.Reason),fault.Operation);
}
}



DashboardFacade()。GetStudentRecord(..)的定义像这样的:

 公共用户GetStudentRecord(用户名字符串)
{
用户的用户= ctx.Users。其中(x => x.ADUserName ==用户名).SingleOrDefault();
回报用户;
}



CTX是我的DbContext。我使用实体框架代码第一次。用户对象是这样的:

 公共类用户
{
公众用户()
{
//的UserDetails =新UserDetail();
}
[关键]
公众的Guid MasterKey {搞定;组; }
公共字符串名字{获得;组; }
公共字符串名字{获得;组; }
公共字符串电子邮件{获得;组; }
公共字符串ADUserName {搞定;组; }
公共字符串用户类型{搞定;组; }
公共虚拟UserDetail的UserDetails {搞定;组; }
公众可空<&日期时间GT; LastModifiedDate {搞定;组; }
}



最后,你可能需要看到在WCF的Web.config应用:

 < XML版本=1.0>? 
<结构>
<&是connectionStrings GT;
<添加名称=NotMyDBContextDB的connectionString =[省略]的providerName =System.Data.SqlClient的/>
<添加名称=ApplicationContext中的connectionString =数据源=;初始目录= MyApp的;集成安全性= TRUE;池=假的providerName =System.Data.SqlClient的/>
< /&是connectionStrings GT;
<&的System.Web GT;
<编译调试=真targetFramework =4.0/>
< /system.web>
< system.serviceModel>
<&行为GT;
< serviceBehaviors>
<&行为GT;
< serviceMetadata httpGetEnabled =真/>
< serviceDebug includeExceptionDetailInFaults =真/>
< /行为>
< / serviceBehaviors>
< /行为>
< serviceHostingEnvironment multipleSiteBindingsEnabled =真/>
< /system.serviceModel>
< system.webServer>
<模块runAllManagedModulesForAllRequests =真/>
<启用directoryBrowse =真/>
< /system.webServer>
< /结构>



任何人都可以指向我,我错了这里在哪里?



这是我得到确切的错误:

 同时接收到http HTTP响应时出现错误: //localhost:5843/MyService.svc。这可能是由于服务端点未使用HTTP协议绑定。这也可能是由于一个HTTP请求上下文服务器(可能是由于服务关停)被中止。请参阅服务器日志的更多细节。 

内部异常:
基础连接已关闭:接收时发生意外错误。

内部异常:
无法读取传输连接的数据:一个现有的连接被强行关闭远程主机。

内部异常:
的现有连接被强行远程主机


解决方案

找到根源了很多脏话和天气有多好之外的思考之后。我删除了的UserDetails虚拟关键字对象,它是用户对象内。



现在它的作品!



至于为什么这导致的一个问题,我的假设是序列化或的DbContext的问题,但我将不得不寻找更多的进去,不知道。



我要去外面现在。



所以,以供参考,如果你在这里结束了,而且不知道是怎么回事,在所有其他的事情你应该看看(大小,超时等):

 检查是否你的对象上有虚拟关键字。 


Before you downvote, I know there are duplicate questions like this one out there, but I tried and did not succeed in finding a solution in them. Could be I missed something, but I am still relatively new to WCF so some of it goes over my head a bit.

I am making this call in my WCF service:

public User GetStudentRecord(string userName)
    {
        try
        {
            return new DashboardFacade().GetStudentRecord(userName);
        }
        catch (Exception ex)
        {
            ServiceFault fault = new ServiceFault();
            fault.Operation = "GetStudentRecord";
            fault.Reason = "Who knows...";
            fault.Message = ex.Message;
            throw new FaultException<ServiceFault>(fault, fault.Message, new FaultCode(fault.Reason), fault.Operation);
        }
    }

DashboardFacade().GetStudentRecord(..) is defined like this:

public User GetStudentRecord(string userName)
{
    User user = ctx.Users.Where(x => x.ADUserName == userName).SingleOrDefault();
    return user;
}

ctx is my DbContext. I am using Entity Framework Code First. The User object looks like this:

public class User
{
    public User()
    {
        //UserDetails = new UserDetail();
    }
    [Key]
    public Guid MasterKey { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Email { get; set; }
    public string ADUserName { get; set; }
    public string UserType { get; set; }
    public virtual UserDetail UserDetails { get; set; }
    public Nullable<DateTime> LastModifiedDate { get; set; }
}

And finally, you probably need to see the web.config on the WCF Application:

<?xml version="1.0"?>
    <configuration>
      <connectionStrings>
        <add name="NotMyDBContextDB" connectionString="[omitted]" providerName="System.Data.SqlClient"/>
        <add name="ApplicationContext" connectionString="Data Source=.;Initial Catalog=MyApp;Integrated Security=True;Pooling=False" providerName="System.Data.SqlClient"/>
      </connectionStrings>
   <system.web>
     <compilation debug="true" targetFramework="4.0"/>
   </system.web>
   <system.serviceModel>
     <behaviors>
       <serviceBehaviors>
          <behavior>
             <serviceMetadata httpGetEnabled="true"/>
             <serviceDebug includeExceptionDetailInFaults="true"/>
          </behavior>
        </serviceBehaviors>
      </behaviors>
      <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>

Can anyone point me to where I am going wrong here?

This is the exact error I am getting:

An error occurred while receiving the HTTP response to http://localhost:5843/MyService.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

Inner Exception:
The underlying connection was closed: An unexpected error occurred on a receive.

Inner Exception:
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

Inner Exception:
An existing connection was forcibly closed by the remote host

解决方案

Found the root cause after a lot of swearing and thinking of how nice the weather is outside. I remove the virtual keyword from the UserDetails object that is inside the User object.

Now it works!

As far as why this caused an issue, my assumptions are serialization or DbContext issues, but I will have to look more into it, not sure.

I'm going outside now.

So for reference, if you wound up here and have no idea what is going on, among all the other things you should look at (size, timeout, etc):

Check to see if your object has virtual keyword on it.

这篇关于WCF - 同时接收HTTP响应为http发生错误:// XXXXX /服务/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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