wcf 数据服务 [webGet] 方法返回 int - 如何读取 int?

发布于 2024-12-21 09:58:36 字数 701 浏览 0 评论 0原文

我有一个返回 int 的 WCF 数据服务 [WebGet] 方法。 (产品表中没有产品)

我如何读取它的结果? 我用浏览器检查了该方法的工作原理。

     public void ProductsCount()
    {
        ctx.BeginExecute<int>(new Uri(uriBase + "/GetNoProducts"), GetProductsCountCompleted, ctx);
    }
    public void GetProductsCountCompleted(IAsyncResult result)
    {
        inventory_db_bigEntities context=result.AsyncState as inventory_db_bigEntities;
        var x = context.EndExecute<int>(result);

       //how do i read the int out of the x variable        
    }

更新

也许 BeginExecute 和 EndExecute 不是正确的方法。

在浏览器窗口中,webget 方法返回:

223863"

I have a WCF data service [WebGet] method returning an int. (no of products in products table)

How can I read it's result?
The method works i checked with the browser.

     public void ProductsCount()
    {
        ctx.BeginExecute<int>(new Uri(uriBase + "/GetNoProducts"), GetProductsCountCompleted, ctx);
    }
    public void GetProductsCountCompleted(IAsyncResult result)
    {
        inventory_db_bigEntities context=result.AsyncState as inventory_db_bigEntities;
        var x = context.EndExecute<int>(result);

       //how do i read the int out of the x variable        
    }

UPDATE

Maybe BeginExecute and EndExecute is not the way to go for it.

In the browser window the webget method returns:

"<GetNoProducts p1:type="Edm.Int32">223863</GetNoProducts>"

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

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

发布评论

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

评论(2

只涨不跌 2024-12-28 09:58:36

IAsyncResultMSDN 页面 使用BeginInvoke 而不是 BeginExecute,然后调用 EndInvoke 取回值:

// The asynchronous method puts the thread id here.
int threadId;

// Create an instance of the test class.
AsyncDemo ad = new AsyncDemo();

// Create the delegate.
AsyncMethodCaller caller = new AsyncMethodCaller(ad.TestMethod);

// Initiate the asychronous call.
IAsyncResult result = caller.BeginInvoke(3000, out threadId, null, null);

...

// Wait for the WaitHandle to become signaled.
result.AsyncWaitHandle.WaitOne();

// Perform additional processing here.
// Call EndInvoke to retrieve the results.
string returnValue = caller.EndInvoke(out threadId, result);

The MSDN page for IAsyncResult uses BeginInvoke rather than BeginExecute and then calls EndInvoke to get the value back:

// The asynchronous method puts the thread id here.
int threadId;

// Create an instance of the test class.
AsyncDemo ad = new AsyncDemo();

// Create the delegate.
AsyncMethodCaller caller = new AsyncMethodCaller(ad.TestMethod);

// Initiate the asychronous call.
IAsyncResult result = caller.BeginInvoke(3000, out threadId, null, null);

...

// Wait for the WaitHandle to become signaled.
result.AsyncWaitHandle.WaitOne();

// Perform additional processing here.
// Call EndInvoke to retrieve the results.
string returnValue = caller.EndInvoke(out threadId, result);
如果没有 2024-12-28 09:58:36

你的例子有什么问题吗? EndExecute 应该可以解决问题...只需调用 FirstOrDefault() 即可获取原始值。或者,如果您不使用 SL,则可以同步执行:

http ://msdn.microsoft.com/en-us/library/hh230677.aspx#ExecutePrimitiveValue

What's wrong with your example? EndExecute should do the trick...just call FirstOrDefault() to get the primitive value. Alternatively, if you're not using SL, you can do it synchronously:

http://msdn.microsoft.com/en-us/library/hh230677.aspx#ExecutePrimitiveValue

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