Wcf 当I';m使用带有书签的DB:调用的目标已引发异常

Wcf 当I';m使用带有书签的DB:调用的目标已引发异常,wcf,workflow-foundation-4,bookmarks,Wcf,Workflow Foundation 4,Bookmarks,我在做WF,我在做书签。 当我写下以下内容时,我可以很好地放弃这项活动: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Activities; using System.Activities.Validation; using Microsoft.VisualBasic.Activities; using System.Windows; usin

我在做WF,我在做书签。 当我写下以下内容时,我可以很好地放弃这项活动:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using System.Activities.Validation;
using Microsoft.VisualBasic.Activities;
using System.Windows;
using System.Data;
using System.Linq;
using SimpleWebDesigner.ServiceReference1;

namespace SimpleWebDesigner.Bookmark_exmple
{
    class newBookmark: NativeActivity
    {

        Service1Client ser = new Service1Client();

        [RequiredArgument]
        public OutArgument<bool> Out_arg { get; set; }//=new OutArgument<string>(output);// { get; set; }

        protected override void Execute(NativeActivityContext context)
        {
            context.CreateBookmark("samename", new BookmarkCallback(OnBookmarkCallback));
        }

        protected override bool CanInduceIdle
        {
            get
            {
                return true;
            }
        }
        void OnBookmarkCallback(NativeActivityContext context, Bookmark bookmark, object val)
        {

            bool approve;
            approve = (bool)ser.get_from_WF(1);
            Out_arg.Set(context, approve);            
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用系统活动;
使用系统、活动、验证;
使用Microsoft.VisualBasic.Activities;
使用System.Windows;
使用系统数据;
使用System.Linq;
使用SimpleWebDesigner.ServiceReference1;
命名空间SimpleWebDesigner.Bookmark\u示例
{
新图书类:本地活动
{
Service1Client ser=newservice1client();
[必需参数]
公共输出参数Out_arg{get;set;}/=新输出参数(output);//{get;set;}
受保护的覆盖无效执行(NativeActivityContext上下文)
{
CreateBookmark(“samename”,newbookmarkcallback(OnBookmarkCallback));
}
受保护的覆盖布尔Caninducidel
{
收到
{
返回true;
}
}
void OnBookmarkCallback(NativeActivityContext上下文、书签书签、对象val)
{
布尔批准;
approve=(bool)ser.get_from_WF(1);
输出参数集(上下文、批准);
}
}
}
喜欢这一页吗

但当我通过WCF从DB读写时,如下代码所示:

class newBookmark: NativeActivity
{
    Service1Client ser = new Service1Client();
    [RequiredArgument]
    public OutArgument<bool> Out_arg { get; set; }//=new OutArgument<string>(output);// { get; set; }

    void OnBookmarkCallback(NativeActivityContext context, Bookmark bookmark, object val)
    {
        bool approve;
        string exp;
        approve = (bool)ser.get_from_WF(1);
        if (approve == true)
            exp = "momo";
        else
            exp = "yoyo";
        Out_arg.Set(context, exp);
}
class newBookmark:NativeActivity
{
Service1Client ser=newservice1client();
[必需参数]
公共输出参数Out_arg{get;set;}/=新输出参数(output);//{get;set;}
void OnBookmarkCallback(NativeActivityContext上下文、书签书签、对象val)
{
布尔批准;
字符串表达式;
approve=(bool)ser.get_from_WF(1);
如果(批准==真)
exp=“momo”;
其他的
exp=“yoyo”;
输出参数集(上下文,exp);
}
当我想删除此活动时,它没有删除,并显示一个弹出窗口,其中有以下错误:调用的目标已引发异常

有什么帮助吗?
谢谢。

鉴于您向我们提供的最少信息,我所能做的就是猜测

Service1Client ser = new Service1Client();
正在导致您的问题。首先,没有理由在设计时创建Service1Client。此外,它建议您在不再需要它时不要处理它


但是,由于您没有显示完整的活动,我不能说构造函数或CacheMatadata()中有代码这是出现错误的另一个原因。

请发布异常的堆栈跟踪。我们无法猜测它来自哪一行。在运行项目之前,当我将它拖放到XMAL文件中时,它不在运行时。您是对的,它来自Service1Client ser=new Service1Client();但我可以用什么替换它呢?我发布了活动的全部代码,并打印了xmal文件的屏幕。感谢您仅在OnBookmarkCallback()中需要时创建Service1Client,并确保调用Close()或Abort()完成后按需要进行。通过这种方式,您可以使连接和会话的打开时间远远超过需要的时间。正如您注意到的,在VS2010中创建服务代理失败,我假设是因为缺少配置元素。在设计时,没有可用的配置信息,这就是Service1Client ctor引发异常的原因。