我在 WCF 服务调用堆栈中的操作被调用,但未完成

发布于 2024-11-09 04:22:36 字数 2460 浏览 0 评论 0原文

我支持 Silverlight 4.0 应用程序,它调用 WCF 服务。当我调试在 IIS 上本地托管的服务时,它会进入此方法,但显然会离开该方法而不会从末尾返回。我没有看到任何异常被调用。

这是业务类中的方法,它不会返回到调用方法。

public string ExecuteMyPortalNonQuery(string CommandConfig, params object[] commandParams)
    {
        MyCompany.MyPortal.DataAccess.SQLDataAccess objSQLDatAcces = new SQLDataAccess();
        objSQLDatAcces.connection = ConfigurationSettings.AppSettings["MyPortalSQLConnection"];

        string SqlQueryString = ConfigurationSettings.AppSettings[CommandConfig];
        if (commandParams != null && commandParams.Length > 0)
            SqlQueryString = string.Format(SqlQueryString, commandParams);
        objSQLDatAcces.executeNonQuery(SqlQueryString);
        return ("SUCCESS");
    }

Edit

这是由操作合约调用的

[OperationContract]
public string UpdateBlahblahList(int Id, int HierarchyId, int PagetypeId, string Name, string Asset, Boolean Default, string ServerName = "", string ServerConnectionString = "")
        {
            MyCompany.MyPortal.DataAccess.SAPAccess sp = new SAPAccess();
            if (Id != 0)
                return (sp.ExecuteMyPortalNonQuery("UpdateBlahblahList", Id, Name, Asset, (Default == true) ? 1 : 0, ServerName, ServerConnectionString));
            else
                return (sp.ExecuteMyPortalNonQuery("InsertBlahblahList", HierarchyId, PagetypeId, Name, Asset, (Default == true) ? 1 : 0, ServerName, ServerConnectionString));
        }

也就是说,在调试时,我发现自己在调用客户端中的 UpdateBlahblahCompleted 方法中,在跳过字符串格式化行之后,SqlQueryString = string.Format( SqlQueryString, commandParams);

objSQLDatAcces.executeNonQuery(SqlQueryString);return ("SUCCESS"); 永远不会达到。

总结一下:

  1. 客户端调用 UpdateBlahblahListAsync
  2. 在服务中到达 [OperationContract] UpdateBlahblahList
  3. 服务方法 UpdateBlahblahList 调用 ExecuteMyPortalNonQuery 但未完成
  4. 客户端使用 client_UpdateBlahblahListCompleted|

重新进入最终的结果是数据库没有得到更新。

是调试造成的吗?我正在使用 VS 2010 的两个实例进行调试。

是否会引发我未观察到的异常?

编辑

感谢西蒙,我知道在哪里观察异常。在客户端的异步完成方法的参数中,最里面的异常消息是:“远程服务器返回错误:NotFound。”。

以下是两个参数的值: 更新 [dbo].[BlahblahXref] SET [PageId] = '{1}',[名称] = '{2}',[资产] = '{3}',[默认] = '{4}',[ ServerName]='{5}',[ServerConnectionString]='{6}' WHERE Id={0}

with

commandParams [] = {375, "测试", "111", 0, "someServerName", "一些长连接字符串"}

I am supporting a Silverlight 4.0 application, which makes a call to a WCF service. As I debug the service, hosted locally on IIS, it makes it to this method but apparently leaves the method without returning from the end. I don't see any exceptions being called.

This is the method in a business class, which stops short of returning to the calling method.

public string ExecuteMyPortalNonQuery(string CommandConfig, params object[] commandParams)
    {
        MyCompany.MyPortal.DataAccess.SQLDataAccess objSQLDatAcces = new SQLDataAccess();
        objSQLDatAcces.connection = ConfigurationSettings.AppSettings["MyPortalSQLConnection"];

        string SqlQueryString = ConfigurationSettings.AppSettings[CommandConfig];
        if (commandParams != null && commandParams.Length > 0)
            SqlQueryString = string.Format(SqlQueryString, commandParams);
        objSQLDatAcces.executeNonQuery(SqlQueryString);
        return ("SUCCESS");
    }

Edit

This is called by the operation contract

[OperationContract]
public string UpdateBlahblahList(int Id, int HierarchyId, int PagetypeId, string Name, string Asset, Boolean Default, string ServerName = "", string ServerConnectionString = "")
        {
            MyCompany.MyPortal.DataAccess.SAPAccess sp = new SAPAccess();
            if (Id != 0)
                return (sp.ExecuteMyPortalNonQuery("UpdateBlahblahList", Id, Name, Asset, (Default == true) ? 1 : 0, ServerName, ServerConnectionString));
            else
                return (sp.ExecuteMyPortalNonQuery("InsertBlahblahList", HierarchyId, PagetypeId, Name, Asset, (Default == true) ? 1 : 0, ServerName, ServerConnectionString));
        }

That is, when debugging, I find myself in the calling client right in the UpdateBlahblahCompleted method after stepping over the string formatting line, SqlQueryString = string.Format(SqlQueryString, commandParams);

The lines objSQLDatAcces.executeNonQuery(SqlQueryString); and return ("SUCCESS"); are never reached.

To sum up:

  1. Client calls UpdateBlahblahListAsync
  2. In the service the [OperationContract] UpdateBlahblahList is reached
  3. Service method UpdateBlahblahList calls ExecuteMyPortalNonQuery but doesn't finish
  4. Client reenters with client_UpdateBlahblahListCompleted|

The net effect is that the database does not get updated.

Is debugging causing this? I'm debugging with two instances of VS 2010.

Can an exception be thrown that I haven't observed?

Edit

Thanks to Simon, I know where to observe the exception. In the Client's Async completed method's Args was the innermost exception message: "The remote server returned an error: NotFound.".

Here are the values for the two parameters:
UPDATE [dbo].[BlahblahXref] SET [PageId] = '{1}', [Name] = '{2}', [Asset] = '{3}', [Default] = '{4}', [ServerName]='{5}',[ServerConnectionString]='{6}' WHERE Id={0}

with

commandParams [] = {375, "Test", "111", 0, "someServerName", "some long connection string"}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

混吃等死 2024-11-16 04:22:36

在托管应用程序(Web 或控制台等)的配置文件中,您可以添加以下行来启用跟踪日志记录:

    <system.diagnostics>
    <sources>
        <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
            <listeners>
                <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="Services.svclog"  />
            </listeners>
        </source>
    </sources>
</system.diagnostics>

然后再次重现您的错误,打开“Services.svclog”,您将能够看到 wcf- 的详细信息包括异常详细信息的调用。

In the config file of your hosting application (web or console, whatever), you can put following lines to enable trace logging:

    <system.diagnostics>
    <sources>
        <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
            <listeners>
                <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="Services.svclog"  />
            </listeners>
        </source>
    </sources>
</system.diagnostics>

then reproduce your bug again, open "Services.svclog", and you will be able to see details of wcf-calls including exception details.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文